Merge change Ica46d149 into eclair

* changes:
  SDK Updater: platform dependency on tools, addon dependency on platform.
diff --git a/samples/ApiDemos/default.properties b/samples/ApiDemos/default.properties
deleted file mode 100644
index 4e561dc..0000000
--- a/samples/ApiDemos/default.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-# 
-# This file must be checked in Version Control Systems.
-# 
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=android-Eclair
diff --git a/samples/CubeLiveWallpaper/Android.mk b/samples/CubeLiveWallpaper/Android.mk
new file mode 100644
index 0000000..7227394
--- /dev/null
+++ b/samples/CubeLiveWallpaper/Android.mk
@@ -0,0 +1,27 @@
+#
+# Copyright (C) 2009 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := CubeLiveWallpapers
+LOCAL_CERTIFICATE := shared
+
+include $(BUILD_PACKAGE)
diff --git a/samples/CubeLiveWallpaper/AndroidManifest.xml b/samples/CubeLiveWallpaper/AndroidManifest.xml
new file mode 100644
index 0000000..8d24c4a
--- /dev/null
+++ b/samples/CubeLiveWallpaper/AndroidManifest.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+<manifest
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.livecubes">
+
+    <application
+        android:label="@string/wallpapers"
+        android:icon="@drawable/ic_launcher_wallpaper">
+
+        <service
+            android:label="@string/wallpaper_cube1"
+            android:name=".cube1.CubeWallpaper1"
+            android:permission="android.permission.BIND_WALLPAPER">
+            <intent-filter>
+                <action android:name="android.service.wallpaper.WallpaperService" />
+            </intent-filter>
+            <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube1" />
+        </service>
+
+        <service
+            android:label="@string/wallpaper_cube2"
+            android:name=".cube2.CubeWallpaper2"
+            android:permission="android.permission.BIND_WALLPAPER">
+            <intent-filter>
+                <action android:name="android.service.wallpaper.WallpaperService" />
+            </intent-filter>
+            <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube2" />
+        </service>
+        <activity
+            android:label="@string/cube2_settings"
+            android:name="com.android.livecubes.cube2.CubeWallpaper2Settings"
+            android:theme="@android:style/Theme.Light.WallpaperSettings"
+            android:exported="true">
+        </activity>
+
+        <service
+            android:label="@string/wallpaper_cube3"
+            android:name=".cube3.CubeWallpaper3"
+            android:permission="android.permission.BIND_WALLPAPER">
+            <intent-filter>
+                <action android:name="android.service.wallpaper.WallpaperService" />
+            </intent-filter>
+            <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube3" />
+        </service>
+
+    </application>
+
+</manifest>
diff --git a/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2 b/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2
diff --git a/samples/CubeLiveWallpaper/NOTICE b/samples/CubeLiveWallpaper/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/samples/CubeLiveWallpaper/NOTICE
@@ -0,0 +1,190 @@
+
+   Copyright (c) 2005-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.
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
diff --git a/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png b/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png
new file mode 100644
index 0000000..965fb71
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png
Binary files differ
diff --git a/samples/CubeLiveWallpaper/res/raw/cube.rs b/samples/CubeLiveWallpaper/res/raw/cube.rs
new file mode 100644
index 0000000..407d63b
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/raw/cube.rs
@@ -0,0 +1,50 @@
+// Copyright (C) 2009 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+#pragma stateVertex(PVBackground)
+
+#define RSID_POINTS 0
+
+void dumpState() {
+
+//    debugF("@@@@@ yrot: ", State->yRotation);
+
+}
+
+int main(int launchID) {
+
+    int i;
+
+    // Change the model matrix to account for the large model
+    // and to do the necessary rotations.
+    float mat1[16];
+    float rads = ((float)startTimeMillis()) / 1000;
+    float xrot = degf(-rads);
+    float yrot = State->yRotation;
+    float scale = 1.0/900.0;
+    matrixLoadScale(mat1, scale, scale, scale);
+    matrixRotate(mat1, yrot, 0.f, 1.f, 0.f);
+    matrixRotate(mat1, xrot, 1.f, 0.f, 0.f);
+    vpLoadModelMatrix(mat1);
+
+    // Draw the cube. The default color will be used,
+    // but we can also set the color here with the color()
+    // function, or specify the color(s) as part of
+    // the vertex data.
+    uploadToBufferObject(NAMED_PointBuffer);
+    drawSimpleMesh(NAMED_CubeMesh);
+
+    return 1;
+}
diff --git a/samples/CubeLiveWallpaper/res/values/shapes.xml b/samples/CubeLiveWallpaper/res/values/shapes.xml
new file mode 100644
index 0000000..49bdaf9
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/values/shapes.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+* Copyright (C) 4008 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT 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-array name="cube2_shapenames">
+        <item>"Cube"</item>
+        <item>"Dodecahedron"</item>
+    </string-array>
+
+    <string-array name="cube2_shapeprefix">
+        <item>"cube"</item>
+        <item>"dodecahedron"</item>
+    </string-array>
+
+    <!-- x,y,z tuples for the points defining the object -->
+    <!-- stored as strings for easier human readability -->
+    <string-array name="cubepoints">
+        <item>"-400 -400 -400"</item>
+        <item>"400 -400 -400"</item>
+        <item>"400 400 -400"</item>
+        <item>"-400 400 -400"</item>
+        <item>"-400 -400 400"</item>
+        <item>"400 -400 400"</item>
+        <item>"400 400 400"</item>
+        <item>"-400 400 400"</item>
+    </string-array>
+
+    <!-- start,end point index tuples of the lines defining the object -->
+    <string-array name="cubelines">
+        <!-- lines forming one face -->
+        <item>"0 1"</item>
+        <item>"1 2"</item>
+        <item>"2 3"</item>
+        <item>"3 0"</item>
+
+        <!-- lines forming the opposite face -->
+        <item>"4 5"</item>
+        <item>"5 6"</item>
+        <item>"6 7"</item>
+        <item>"7 4"</item>
+
+        <!-- lines connecting the two faces -->
+        <item>"0 4"</item>
+        <item>"1 5"</item>
+        <item>"2 6"</item>
+        <item>"3 7"</item>
+    </string-array>
+
+    <string-array name="dodecahedronpoints">
+        <item>"333.850000 0.000000 437.250000"</item>
+        <item>"103.400000 317.350000 437.250000"</item>
+        <item>"-270.050000 196.350000 437.250000"</item>
+        <item>"-270.050000 -196.350000 437.250000"</item>
+        <item>"103.400000 -317.350000 437.250000"</item>
+        <item>"540.100000 0.000000 103.400000"</item>
+        <item>"167.200000 513.700000 103.400000"</item>
+        <item>"-437.250000 317.350000 103.400000"</item>
+        <item>"-437.250000 -317.350000 103.400000"</item>
+        <item>"167.200000 -513.700000 103.400000"</item>
+        <item>"437.250000 317.350000 -103.400000"</item>
+        <item>"-167.200000 513.700000 -103.400000"</item>
+        <item>"-540.100000 0.000000 -103.400000"</item>
+        <item>"-167.200000 -513.700000 -103.400000"</item>
+        <item>"437.250000 -317.350000 -103.400000"</item>
+        <item>"270.050000 196.350000 -437.250000"</item>
+        <item>"-103.400000 317.350000 -437.250000"</item>
+        <item>"-333.850000 0.000000 -437.250000"</item>
+        <item>"-103.400000 -317.350000 -437.250000"</item>
+        <item>"270.050000 -196.350000 -437.250000"</item>
+    </string-array>
+
+    <string-array name="dodecahedronlines">
+        <item>"0 1"</item>
+        <item>"0 4"</item>
+        <item>"0 5"</item>
+        <item>"1 2"</item>
+        <item>"1 6"</item>
+        <item>"2 3"</item>
+        <item>"2 7"</item>
+        <item>"3 4"</item>
+        <item>"3 8"</item>
+        <item>"4 9"</item>
+        <item>"5 10"</item>
+        <item>"5 14"</item>
+        <item>"6 10"</item>
+        <item>"6 11"</item>
+        <item>"7 11"</item>
+        <item>"7 12"</item>
+        <item>"8 12"</item>
+        <item>"8 13"</item>
+        <item>"9 13"</item>
+        <item>"9 14"</item>
+        <item>"10 15"</item>
+        <item>"11 16"</item>
+        <item>"12 17"</item>
+        <item>"13 18"</item>
+        <item>"14 19"</item>
+        <item>"15 16"</item>
+        <item>"15 19"</item>
+        <item>"16 17"</item>
+        <item>"17 18"</item>
+        <item>"18 19"</item>
+    </string-array>
+</resources>
diff --git a/samples/CubeLiveWallpaper/res/values/strings.xml b/samples/CubeLiveWallpaper/res/values/strings.xml
new file mode 100644
index 0000000..3302058
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/values/strings.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+* 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.
+*/
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <!-- General -->
+    <skip />
+    <!-- Application name -->
+    <string name="wallpapers">Example Wallpapers</string>
+
+    <!-- Wallpaper showing a cube -->
+    <string name="wallpaper_cube1">Cube</string>
+
+    <!-- Wallpaper showing a cube or dodecahedron, data read from resource -->
+    <string name="wallpaper_cube2">Cube - resource</string>
+
+    <!-- Wallpaper showing a cube, renderscript version -->
+    <string name="wallpaper_cube3">Cube - RenderScript</string>
+
+    <string name="cube2_settings">Settings</string>
+    <string name="cube2_settings_title">Select shape</string>
+    <string name="cube2_settings_summary">Choose whether to display a cube or a dodecahedron</string>
+</resources>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube1.xml b/samples/CubeLiveWallpaper/res/xml/cube1.xml
new file mode 100644
index 0000000..5c7fca5
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube1.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * 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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+/>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube2.xml b/samples/CubeLiveWallpaper/res/xml/cube2.xml
new file mode 100644
index 0000000..bf9054c
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube2.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * 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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+        android:settingsActivity="com.android.livecubes.cube2.CubeWallpaper2Settings"
+/>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml b/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml
new file mode 100644
index 0000000..50a28ae
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        android:title="@string/cube2_settings"
+        android:key="cube2wallpaper_settings">
+
+    <ListPreference
+            android:key="cube2_shape"
+            android:title="@string/cube2_settings_title"
+            android:summary="@string/cube2_settings_summary"
+            android:entries="@array/cube2_shapenames"
+            android:entryValues="@array/cube2_shapeprefix" />
+
+</PreferenceScreen>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube3.xml b/samples/CubeLiveWallpaper/res/xml/cube3.xml
new file mode 100644
index 0000000..5c7fca5
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube3.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/**
+ * 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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+/>
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java
new file mode 100644
index 0000000..9279065
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java
@@ -0,0 +1,240 @@
+/*
+ * 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.livecubes.cube1;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.SystemClock;
+import android.service.wallpaper.WallpaperService;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+
+/*
+ * This animated wallpaper draws a rotating wireframe cube.
+ */
+public class CubeWallpaper1 extends WallpaperService {
+
+    private final Handler mHandler = new Handler();
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+    }
+
+    @Override
+    public Engine onCreateEngine() {
+        return new CubeEngine();
+    }
+
+    class CubeEngine extends Engine {
+
+        private final Paint mPaint = new Paint();
+        private float mOffset;
+        private float mTouchX = -1;
+        private float mTouchY = -1;
+        private long mStartTime;
+        private float mCenterX;
+        private float mCenterY;
+
+        private final Runnable mDrawCube = new Runnable() {
+            public void run() {
+                drawFrame();
+            }
+        };
+        private boolean mVisible;
+
+        CubeEngine() {
+            // Create a Paint to draw the lines for our cube
+            final Paint paint = mPaint;
+            paint.setColor(0xffffffff);
+            paint.setAntiAlias(true);
+            paint.setStrokeWidth(2);
+            paint.setStrokeCap(Paint.Cap.ROUND);
+            paint.setStyle(Paint.Style.STROKE);
+
+            mStartTime = SystemClock.elapsedRealtime();
+        }
+
+        @Override
+        public void onCreate(SurfaceHolder surfaceHolder) {
+            super.onCreate(surfaceHolder);
+
+            // By default we don't get touch events, so enable them.
+            setTouchEventsEnabled(true);
+        }
+
+        @Override
+        public void onDestroy() {
+            super.onDestroy();
+            mHandler.removeCallbacks(mDrawCube);
+        }
+
+        @Override
+        public void onVisibilityChanged(boolean visible) {
+            mVisible = visible;
+            if (visible) {
+                drawFrame();
+            } else {
+                mHandler.removeCallbacks(mDrawCube);
+            }
+        }
+
+        @Override
+        public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+            super.onSurfaceChanged(holder, format, width, height);
+            // store the center of the surface, so we can draw the cube in the right spot
+            mCenterX = width/2.0f;
+            mCenterY = height/2.0f;
+            drawFrame();
+        }
+
+        @Override
+        public void onSurfaceCreated(SurfaceHolder holder) {
+            super.onSurfaceCreated(holder);
+        }
+
+        @Override
+        public void onSurfaceDestroyed(SurfaceHolder holder) {
+            super.onSurfaceDestroyed(holder);
+            mVisible = false;
+            mHandler.removeCallbacks(mDrawCube);
+        }
+
+        @Override
+        public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+            mOffset = xOffset;
+            drawFrame();
+        }
+
+        /*
+         * Store the position of the touch event so we can use it for drawing later
+         */
+        @Override
+        public void onTouchEvent(MotionEvent event) {
+            if (event.getAction() == MotionEvent.ACTION_MOVE) {
+                mTouchX = event.getX();
+                mTouchY = event.getY();
+            } else {
+                mTouchX = -1;
+                mTouchY = -1;
+            }
+            super.onTouchEvent(event);
+        }
+
+        /*
+         * Draw one frame of the animation. This method gets called repeatedly
+         * by posting a delayed Runnable. You can do any drawing you want in
+         * here. This example draws a wireframe cube.
+         */
+        void drawFrame() {
+            final SurfaceHolder holder = getSurfaceHolder();
+
+            Canvas c = null;
+            try {
+                c = holder.lockCanvas();
+                if (c != null) {
+                    // draw something
+                    drawCube(c);
+                    drawTouchPoint(c);
+                }
+            } finally {
+                if (c != null) holder.unlockCanvasAndPost(c);
+            }
+
+            // Reschedule the next redraw
+            mHandler.removeCallbacks(mDrawCube);
+            if (mVisible) {
+                mHandler.postDelayed(mDrawCube, 1000 / 25);
+            }
+        }
+
+        /*
+         * Draw a wireframe cube by drawing 12 3 dimensional lines between
+         * adjacent corners of the cube
+         */
+        void drawCube(Canvas c) {
+            c.save();
+            c.translate(mCenterX, mCenterY);
+            c.drawColor(0xff000000);
+            drawLine(c, -400, -400, -400,  400, -400, -400);
+            drawLine(c,  400, -400, -400,  400,  400, -400);
+            drawLine(c,  400,  400, -400, -400,  400, -400);
+            drawLine(c, -400,  400, -400, -400, -400, -400);
+
+            drawLine(c, -400, -400,  400,  400, -400,  400);
+            drawLine(c,  400, -400,  400,  400,  400,  400);
+            drawLine(c,  400,  400,  400, -400,  400,  400);
+            drawLine(c, -400,  400,  400, -400, -400,  400);
+
+            drawLine(c, -400, -400,  400, -400, -400, -400);
+            drawLine(c,  400, -400,  400,  400, -400, -400);
+            drawLine(c,  400,  400,  400,  400,  400, -400);
+            drawLine(c, -400,  400,  400, -400,  400, -400);
+            c.restore();
+        }
+
+        /*
+         * Draw a 3 dimensional line on to the screen
+         */
+        void drawLine(Canvas c, int x1, int y1, int z1, int x2, int y2, int z2) {
+            long now = SystemClock.elapsedRealtime();
+            float xrot = ((float)(now - mStartTime)) / 1000;
+            float yrot = (0.5f - mOffset) * 2.0f;
+            float zrot = 0;
+
+            // 3D transformations
+
+            // rotation around X-axis
+            float newy1 = (float)(Math.sin(xrot) * z1 + Math.cos(xrot) * y1);
+            float newy2 = (float)(Math.sin(xrot) * z2 + Math.cos(xrot) * y2);
+            float newz1 = (float)(Math.cos(xrot) * z1 - Math.sin(xrot) * y1);
+            float newz2 = (float)(Math.cos(xrot) * z2 - Math.sin(xrot) * y2);
+
+            // rotation around Y-axis
+            float newx1 = (float)(Math.sin(yrot) * newz1 + Math.cos(yrot) * x1);
+            float newx2 = (float)(Math.sin(yrot) * newz2 + Math.cos(yrot) * x2);
+            newz1 = (float)(Math.cos(yrot) * newz1 - Math.sin(yrot) * x1);
+            newz2 = (float)(Math.cos(yrot) * newz2 - Math.sin(yrot) * x2);
+
+            // 3D-to-2D projection
+            float startX = newx1 / (4 - newz1 / 400);
+            float startY = newy1 / (4 - newz1 / 400);
+            float stopX =  newx2 / (4 - newz2 / 400);
+            float stopY =  newy2 / (4 - newz2 / 400);
+
+            c.drawLine(startX, startY, stopX, stopY, mPaint);
+        }
+
+        /*
+         * Draw a circle around the current touch point, if any.
+         */
+        void drawTouchPoint(Canvas c) {
+            if (mTouchX >=0 && mTouchY >= 0) {
+                c.drawCircle(mTouchX, mTouchY, 80, mPaint);
+            }
+        }
+
+    }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java
new file mode 100644
index 0000000..43f1326
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java
@@ -0,0 +1,296 @@
+/*
+ * 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.livecubes.cube2;
+
+import com.android.livecubes.R;
+
+import android.content.SharedPreferences;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.SystemClock;
+import android.service.wallpaper.WallpaperService;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+
+/*
+ * This animated wallpaper draws a rotating wireframe shape. It is similar to
+ * example #1, but has a choice of 2 shapes, which are user selectable and
+ * defined in resources instead of in code.
+ */
+
+public class CubeWallpaper2 extends WallpaperService {
+
+    public static final String SHARED_PREFS_NAME="cube2settings";
+
+    static class ThreeDPoint {
+        float x;
+        float y;
+        float z;
+    }
+
+    static class ThreeDLine {
+        int startPoint;
+        int endPoint;
+    }
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+    }
+
+    @Override
+    public Engine onCreateEngine() {
+        return new CubeEngine();
+    }
+
+    class CubeEngine extends Engine 
+        implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+        private final Handler mHandler = new Handler();
+
+        ThreeDPoint [] mOriginalPoints;
+        ThreeDPoint [] mRotatedPoints;
+        ThreeDLine [] mLines;
+        private final Paint mPaint = new Paint();
+        private float mOffset;
+        private float mTouchX = -1;
+        private float mTouchY = -1;
+        private long mStartTime;
+        private float mCenterX;
+        private float mCenterY;
+
+        private final Runnable mDrawCube = new Runnable() {
+            public void run() {
+                drawFrame();
+            }
+        };
+        private boolean mVisible;
+        private SharedPreferences mPrefs;
+
+        CubeEngine() {
+            // Create a Paint to draw the lines for our cube
+            final Paint paint = mPaint;
+            paint.setColor(0xffffffff);
+            paint.setAntiAlias(true);
+            paint.setStrokeWidth(2);
+            paint.setStrokeCap(Paint.Cap.ROUND);
+            paint.setStyle(Paint.Style.STROKE);
+
+            mStartTime = SystemClock.elapsedRealtime();
+
+            mPrefs = CubeWallpaper2.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
+            mPrefs.registerOnSharedPreferenceChangeListener(this);
+            onSharedPreferenceChanged(mPrefs, null);
+        }
+
+        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+
+            String shape = prefs.getString("cube2_shape", "cube");
+
+            // read the 3D model from the resource
+            readModel(shape);
+        }
+
+        private void readModel(String prefix) {
+            // Read the model definition in from a resource.
+
+            // get the resource identifiers for the arrays for the selected shape
+            int pid = getResources().getIdentifier(prefix + "points", "array", getPackageName());
+            int lid = getResources().getIdentifier(prefix + "lines", "array", getPackageName());
+
+            String [] p = getResources().getStringArray(pid);
+            int numpoints = p.length;
+            mOriginalPoints = new ThreeDPoint[numpoints];
+            mRotatedPoints = new ThreeDPoint[numpoints];
+
+            for (int i = 0; i < numpoints; i++) {
+                mOriginalPoints[i] = new ThreeDPoint();
+                mRotatedPoints[i] = new ThreeDPoint();
+                String [] coord = p[i].split(" ");
+                mOriginalPoints[i].x = Float.valueOf(coord[0]);
+                mOriginalPoints[i].y = Float.valueOf(coord[1]);
+                mOriginalPoints[i].z = Float.valueOf(coord[2]);
+            }
+
+            String [] l = getResources().getStringArray(lid);
+            int numlines = l.length;
+            mLines = new ThreeDLine[numlines];
+
+            for (int i = 0; i < numlines; i++) {
+                mLines[i] = new ThreeDLine();
+                String [] idx = l[i].split(" ");
+                mLines[i].startPoint = Integer.valueOf(idx[0]);
+                mLines[i].endPoint = Integer.valueOf(idx[1]);
+            }
+        }
+
+        @Override
+        public void onCreate(SurfaceHolder surfaceHolder) {
+            super.onCreate(surfaceHolder);
+            setTouchEventsEnabled(true);
+        }
+
+        @Override
+        public void onDestroy() {
+            super.onDestroy();
+            mHandler.removeCallbacks(mDrawCube);
+        }
+
+        @Override
+        public void onVisibilityChanged(boolean visible) {
+            mVisible = visible;
+            if (visible) {
+                drawFrame();
+            } else {
+                mHandler.removeCallbacks(mDrawCube);
+            }
+        }
+
+        @Override
+        public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+            super.onSurfaceChanged(holder, format, width, height);
+            // store the center of the surface, so we can draw the cube in the right spot
+            mCenterX = width/2.0f;
+            mCenterY = height/2.0f;
+            drawFrame();
+        }
+
+        @Override
+        public void onSurfaceCreated(SurfaceHolder holder) {
+            super.onSurfaceCreated(holder);
+        }
+
+        @Override
+        public void onSurfaceDestroyed(SurfaceHolder holder) {
+            super.onSurfaceDestroyed(holder);
+            mVisible = false;
+            mHandler.removeCallbacks(mDrawCube);
+        }
+
+        @Override
+        public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+            mOffset = xOffset;
+            drawFrame();
+        }
+
+        /*
+         * Store the position of the touch event so we can use it for drawing later
+         */
+        @Override
+        public void onTouchEvent(MotionEvent event) {
+            if (event.getAction() == MotionEvent.ACTION_MOVE) {
+                mTouchX = event.getX();
+                mTouchY = event.getY();
+            } else {
+                mTouchX = -1;
+                mTouchY = -1;
+            }
+            super.onTouchEvent(event);
+        }
+
+        /*
+         * Draw one frame of the animation. This method gets called repeatedly
+         * by posting a delayed Runnable. You can do any drawing you want in
+         * here. This example draws a wireframe cube.
+         */
+        void drawFrame() {
+            final SurfaceHolder holder = getSurfaceHolder();
+            final Rect frame = holder.getSurfaceFrame();
+            final int width = frame.width();
+            final int height = frame.height();
+
+            Canvas c = null;
+            try {
+                c = holder.lockCanvas();
+                if (c != null) {
+                    // draw something
+                    drawCube(c);
+                    drawTouchPoint(c);
+                }
+            } finally {
+                if (c != null) holder.unlockCanvasAndPost(c);
+            }
+
+            mHandler.removeCallbacks(mDrawCube);
+            if (mVisible) {
+                mHandler.postDelayed(mDrawCube, 1000 / 25);
+            }
+        }
+
+        void drawCube(Canvas c) {
+            c.save();
+            c.translate(mCenterX, mCenterY);
+            c.drawColor(0xff000000);
+
+            long now = SystemClock.elapsedRealtime();
+            float xrot = ((float)(now - mStartTime)) / 1000;
+            float yrot = (0.5f - mOffset) * 2.0f;
+            rotateAndProjectPoints(xrot, yrot);
+            drawLines(c);
+            c.restore();
+        }
+
+        void rotateAndProjectPoints(float xrot, float yrot) {
+            int n = mOriginalPoints.length;
+            for (int i = 0; i < n; i++) {
+                // rotation around X-axis
+                ThreeDPoint p = mOriginalPoints[i];
+                float x = p.x;
+                float y = p.y;
+                float z = p.z;
+                float newy = (float)(Math.sin(xrot) * z + Math.cos(xrot) * y);
+                float newz = (float)(Math.cos(xrot) * z - Math.sin(xrot) * y);
+
+                // rotation around Y-axis
+                float newx = (float)(Math.sin(yrot) * newz + Math.cos(yrot) * x);
+                newz = (float)(Math.cos(yrot) * newz - Math.sin(yrot) * x);
+
+                // 3D-to-2D projection
+                float screenX = newx / (4 - newz / 400);
+                float screenY = newy / (4 - newz / 400);
+
+                mRotatedPoints[i].x = screenX;
+                mRotatedPoints[i].y = screenY;
+                mRotatedPoints[i].z = 0;
+            }
+        }
+
+        void drawLines(Canvas c) {
+            int n = mLines.length;
+            for (int i = 0; i < n; i++) {
+                ThreeDLine l = mLines[i];
+                ThreeDPoint start = mRotatedPoints[l.startPoint];
+                ThreeDPoint end = mRotatedPoints[l.endPoint];
+                c.drawLine(start.x, start.y, end.x, end.y, mPaint);
+            }
+        }
+
+        void drawTouchPoint(Canvas c) {
+            if (mTouchX >=0 && mTouchY >= 0) {
+                c.drawCircle(mTouchX, mTouchY, 80, mPaint);
+            }
+        }
+    }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java
new file mode 100644
index 0000000..feeb0bd
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 Google Inc.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * 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.livecubes.cube2;
+
+import com.android.livecubes.R;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.service.wallpaper.WallpaperSettingsActivity;
+
+public class CubeWallpaper2Settings extends WallpaperSettingsActivity
+    implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+    @Override
+    protected void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        getPreferenceManager().setSharedPreferencesName(
+                CubeWallpaper2.SHARED_PREFS_NAME);
+        addPreferencesFromResource(R.xml.cube2_settings);
+        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
+                this);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+    }
+
+    @Override
+    protected void onDestroy() {
+        getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
+                this);
+        super.onDestroy();
+    }
+
+    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+            String key) {
+        //(new BackupManager(this)).dataChanged();
+    }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java
new file mode 100644
index 0000000..5cfad14
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java
@@ -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.
+ */
+
+package com.android.livecubes.cube3;
+
+import com.android.livecubes.R;
+import com.android.livecubes.RenderScriptScene;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Primitive;
+import android.renderscript.ProgramRaster;
+import android.renderscript.ProgramVertex;
+import android.renderscript.ScriptC;
+import android.renderscript.SimpleMesh;
+import android.renderscript.Type;
+import android.renderscript.Element.Builder;
+
+import java.util.TimeZone;
+
+/*
+ * This example draws a shape whose definition is read from resources (though
+ * it's not user selectable like in example #2), but does the drawing using
+ * RenderScript.
+ */
+class Cube3RS extends RenderScriptScene {
+
+    static class ThreeDPoint {
+        public float x;
+        public float y;
+        public float z;
+    }
+
+    static class ThreeDLine {
+        int startPoint;
+        int endPoint;
+    }
+
+    static class WorldState {
+        public float yRotation;
+        public float mCenterX;
+        public float mCenterY;
+    }
+    ThreeDPoint [] mOriginalPoints;
+    ThreeDLine [] mLines;
+
+    WorldState mWorldState = new WorldState();
+    private Type mStateType;
+    private Allocation mState;
+
+    private SimpleMesh mCubeMesh;
+
+    private Allocation mPointAlloc;
+    private float [] mPointData;
+
+    private Allocation mLineIdxAlloc;
+    private short [] mIndexData;
+
+    private ProgramVertex mPVBackground;
+    private ProgramVertex.MatrixAllocation mPVAlloc;
+
+    private int mWidth;
+    private int mHeight;
+
+    private static final int RSID_STATE = 0;
+    private static final int RSID_POINTS = 1;
+    private static final int RSID_LINES = 2;
+    private static final int RSID_PROGRAMVERTEX = 3;
+
+
+    Cube3RS(int width, int height) {
+        super(width, height);
+        mWidth = width;
+        mHeight = height;
+    }
+
+    @Override
+    public void resize(int width, int height) {
+        super.resize(width, height);
+        mWidth = width;
+        mHeight = height;
+    }
+
+    @Override
+    protected ScriptC createScript() {
+
+        // Read the model in to our point/line objects
+        readModel();
+
+        // Create a renderscript type from a java class. The specified name doesn't
+        // really matter; the name by which we refer to the object in RenderScript
+        // will be specified later.
+        mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
+        // Create an allocation from the type we just created.
+        mState = Allocation.createTyped(mRS, mStateType);
+        // set our java object as the data for the renderscript allocation
+        mWorldState.yRotation = (-0.5f) * 2 * 180 / (float) Math.PI;
+        mState.data(mWorldState);
+
+        /*
+         *  Now put our model in to a form that renderscript can work with:
+         *  - create a buffer of floats that are the coordinates for the points that define the cube
+         *  - create a buffer of integers that are the indices of the points that form lines
+         *  - combine the two in to a mesh
+         */
+
+        // First set up the coordinate system and such
+        ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
+        mPVBackground = pvb.create();
+        mPVBackground.setName("PVBackground");
+        mPVAlloc = new ProgramVertex.MatrixAllocation(mRS);
+        mPVBackground.bindAllocation(mPVAlloc);
+        mPVAlloc.setupProjectionNormalized(mWidth, mHeight);
+
+        // Start creating the mesh
+        final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS);
+
+        // Create the Element for the points
+        Builder elementBuilder = new Builder(mRS);
+        // By specifying a prefix, even an empty one, the members will be accessible
+        // in the renderscript. If we just called addFloatXYZ(), the members would be
+        // unnamed in the renderscript struct definition.
+        elementBuilder.addFloatXYZ("");
+        final Element vertexElement = elementBuilder.create();
+        final int vertexSlot = meshBuilder.addVertexType(vertexElement, mOriginalPoints.length);
+        // Specify the type and number of indices we need. We'll allocate them later.
+        meshBuilder.setIndexType(Element.INDEX_16(mRS), mLines.length * 2);
+        // This will be a line mesh
+        meshBuilder.setPrimitive(Primitive.LINE);
+
+        // Create the Allocation for the vertices
+        mCubeMesh = meshBuilder.create();
+        mCubeMesh.setName("CubeMesh");
+        mPointAlloc = mCubeMesh.createVertexAllocation(vertexSlot);
+        mPointAlloc.setName("PointBuffer");
+
+        // Create the Allocation for the indices
+        mLineIdxAlloc = mCubeMesh.createIndexAllocation();
+
+        // Bind the allocations to the mesh
+        mCubeMesh.bindVertexAllocation(mPointAlloc, 0);
+        mCubeMesh.bindIndexAllocation(mLineIdxAlloc);
+
+        /*
+         *  put the vertex and index data in their respective buffers
+         */
+        // one float each for x, y and z, and the 4th float will hold rgba
+        mPointData = new float[mOriginalPoints.length * 3];
+        for(int i = 0; i < mOriginalPoints.length; i ++) {
+            mPointData[i*3]   = mOriginalPoints[i].x;
+            mPointData[i*3+1] = mOriginalPoints[i].y;
+            mPointData[i*3+2] = mOriginalPoints[i].z;
+        }
+        mIndexData = new short[mLines.length * 2];
+        for(int i = 0; i < mLines.length; i++) {
+            mIndexData[i * 2] = (short)(mLines[i].startPoint);
+            mIndexData[i * 2 + 1] = (short)(mLines[i].endPoint);
+        }
+
+        /*
+         *  upload the vertex and index data
+         */
+        mPointAlloc.data(mPointData);
+        mPointAlloc.uploadToBufferObject();
+        mLineIdxAlloc.data(mIndexData);
+        mLineIdxAlloc.uploadToBufferObject();
+
+        // Time to create the script
+        ScriptC.Builder sb = new ScriptC.Builder(mRS);
+        // Specify the name by which to refer to the WorldState object in the
+        // renderscript.
+        sb.setType(mStateType, "State", RSID_STATE);
+        sb.setType(mCubeMesh.getVertexType(0), "Points", RSID_POINTS);
+        // this crashes when uncommented
+        //sb.setType(mCubeMesh.getIndexType(), "Lines", RSID_LINES);
+
+        // Set the render script that will make use of the objects we defined above
+        sb.setScript(mResources, R.raw.cube);
+        sb.setRoot(true);
+
+        ScriptC script = sb.create();
+        script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+        script.setTimeZone(TimeZone.getDefault().getID());
+
+        script.bindAllocation(mState, RSID_STATE);
+        script.bindAllocation(mPointAlloc, RSID_POINTS);
+        script.bindAllocation(mLineIdxAlloc, RSID_LINES);
+        script.bindAllocation(mPVAlloc.mAlloc, RSID_PROGRAMVERTEX);
+
+        return script;
+    }
+
+    @Override
+    public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
+        // update our state, then push it to the renderscript
+        mWorldState.yRotation = (xOffset - 0.5f) * 2 * 180 / (float) Math.PI;
+        mState.data(mWorldState);
+    }
+
+    /*
+     *  Read the model definition from the resource.
+     */
+    private void readModel() {
+
+        String [] p = mResources.getStringArray(R.array.cubepoints);
+        int numpoints = p.length;
+        mOriginalPoints = new ThreeDPoint[numpoints];
+
+        for (int i = 0; i < numpoints; i++) {
+            mOriginalPoints[i] = new ThreeDPoint();
+            String [] coord = p[i].split(" ");
+            mOriginalPoints[i].x = Float.valueOf(coord[0]);
+            mOriginalPoints[i].y = Float.valueOf(coord[1]);
+            mOriginalPoints[i].z = Float.valueOf(coord[2]);
+        }
+
+        String [] l = mResources.getStringArray(R.array.cubelines);
+        int numlines = l.length;
+        mLines = new ThreeDLine[numlines];
+
+        for (int i = 0; i < numlines; i++) {
+            mLines[i] = new ThreeDLine();
+            String [] idx = l[i].split(" ");
+            mLines[i].startPoint = Integer.valueOf(idx[0]);
+            mLines[i].endPoint = Integer.valueOf(idx[1]);
+        }
+    }
+
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java
new file mode 100644
index 0000000..8f09388
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java
@@ -0,0 +1,28 @@
+/*
+ * 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.livecubes.cube3;
+
+import com.android.livecubes.RenderScriptWallpaper;
+
+public class CubeWallpaper3 extends RenderScriptWallpaper<Cube3RS> {
+
+    @Override
+    protected Cube3RS createScene(int width, int height) {
+        return new Cube3RS(width, height);
+    }
+}
+
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java
new file mode 100644
index 0000000..429e93d
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java
@@ -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.
+ */
+
+
+package com.android.livecubes;
+
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptC;
+
+public abstract class RenderScriptScene {
+    protected int mWidth;
+    protected int mHeight;
+    protected boolean mPreview;
+    protected Resources mResources;
+    protected RenderScript mRS;
+    protected ScriptC mScript;
+
+    public RenderScriptScene(int width, int height) {
+        mWidth = width;
+        mHeight = height;
+    }
+
+    public void init(RenderScript rs, Resources res, boolean isPreview) {
+        mRS = rs;
+        mResources = res;
+        mPreview = isPreview;
+        mScript = createScript();
+    }
+
+    public boolean isPreview() {
+        return mPreview;
+    }
+
+    public int getWidth() {
+        return mWidth;
+    }
+
+    public int getHeight() {
+        return mHeight;
+    }
+
+    public Resources getResources() {
+        return mResources;
+    }
+
+    public RenderScript getRS() {
+        return mRS;
+    }
+
+    public ScriptC getScript() {
+        return mScript;
+    }
+
+    protected abstract ScriptC createScript();
+
+    public void stop() {
+        mRS.contextBindRootScript(null);
+    }
+
+    public void start() {
+        mRS.contextBindRootScript(mScript);
+    }
+
+    public void resize(int width, int height) {
+        mWidth = width;
+        mHeight = height;
+    }
+
+    @SuppressWarnings({"UnusedDeclaration"})
+    public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
+    }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java
new file mode 100644
index 0000000..c30a619
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java
@@ -0,0 +1,106 @@
+/*
+ * 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.livecubes;
+
+import android.service.wallpaper.WallpaperService;
+import android.renderscript.RenderScript;
+import android.view.SurfaceHolder;
+import android.view.Surface;
+
+public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends WallpaperService {
+    public Engine onCreateEngine() {
+        return new RenderScriptEngine();
+    }
+
+    protected abstract T createScene(int width, int height);
+
+    private class RenderScriptEngine extends Engine {
+        private RenderScript mRs;
+        private T mRenderer;
+
+        @Override
+        public void onCreate(SurfaceHolder surfaceHolder) {
+            super.onCreate(surfaceHolder);
+            setTouchEventsEnabled(false);
+            surfaceHolder.setSizeFromLayout();
+        }
+
+        @Override
+        public void onDestroy() {
+            super.onDestroy();
+            destroyRenderer();
+        }
+
+        private void destroyRenderer() {
+            if (mRenderer != null) {
+                mRenderer.stop();
+                mRenderer = null;
+            }
+            if (mRs != null) {
+                mRs.destroy();
+                mRs = null;
+            }
+        }
+
+        @Override
+        public void onVisibilityChanged(boolean visible) {
+            super.onVisibilityChanged(visible);
+            if (mRenderer != null) {
+                if (visible) {
+                    mRenderer.start();
+                } else {
+                    mRenderer.stop();
+                }
+            }
+        }
+
+        @Override
+        public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+            super.onSurfaceChanged(holder, format, width, height);
+            if (mRenderer == null) {
+                mRenderer = createScene(width, height);
+                mRenderer.init(mRs, getResources(), isPreview());
+                mRenderer.start();
+            } else {
+                mRenderer.resize(width, height);
+            }
+        }
+
+        @Override
+        public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+            mRenderer.setOffset(xOffset, yOffset, xPixels, yPixels);
+        }
+
+        @Override
+        public void onSurfaceCreated(SurfaceHolder holder) {
+            super.onSurfaceCreated(holder);
+
+            Surface surface = null;
+            while (surface == null) {
+                surface = holder.getSurface();
+            }
+            mRs = new RenderScript(surface, false, false);
+        }
+
+        @Override
+        public void onSurfaceDestroyed(SurfaceHolder holder) {
+            super.onSurfaceDestroyed(holder);
+            destroyRenderer();
+        }
+    }
+}
diff --git a/testrunner/test_defs.xml b/testrunner/test_defs.xml
index 04fcf99..adb854e 100644
--- a/testrunner/test_defs.xml
+++ b/testrunner/test_defs.xml
@@ -317,6 +317,13 @@
     coverage_target="framework"
     cts="true" />
 
+<test name="cts-webkit"
+    build_path="cts/tests/tests/webkit"
+    package="com.android.cts.webkit"
+    runner="android.test.InstrumentationCtsTestRunner"
+    coverage_target="framework"
+    cts="true" />
+
 <test name="cts-widget"
     build_path="cts/tests/tests/widget"
     package="com.android.cts.widget"
diff --git a/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java b/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
index e2d8c35..a70086d 100644
--- a/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
+++ b/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
@@ -35,6 +35,11 @@
  * to {@link com.android.layoutopt.uix.LayoutAnalysis} and {@link org.w3c.dom.Node}.
  */
 public class LayoutAnalysisCategory {
+    private static final String ANDROID_PADDING = "android:padding";
+    private static final String ANDROID_PADDING_LEFT = "android:paddingLeft";
+    private static final String ANDROID_PADDING_TOP = "android:paddingTop";
+    private static final String ANDROID_PADDING_RIGHT = "android:paddingRight";
+    private static final String ANDROID_PADDING_BOTTOM = "android:paddingBottom";
     private static final String ANDROID_LAYOUT_WIDTH = "android:layout_width";
     private static final String ANDROID_LAYOUT_HEIGHT = "android:layout_height";
     private static final String VALUE_FILL_PARENT = "fill_parent";
@@ -98,8 +103,20 @@
                 node.getUserData(XmlDocumentBuilder.NODE_END_LINE);
         return data == null ? -1 : (Integer) data;
     }
-    
-    
+
+    /**
+     * xmlNode.hasPadding()
+     * 
+     * @return True if the node has one ore more padding attributes.
+     */
+    public static boolean hasPadding(Element element) {
+        return element.getAttribute(ANDROID_PADDING).length() > 0 ||
+                element.getAttribute(ANDROID_PADDING_LEFT).length() > 0 ||
+                element.getAttribute(ANDROID_PADDING_TOP).length() > 0 ||
+                element.getAttribute(ANDROID_PADDING_BOTTOM).length() > 0 ||
+                element.getAttribute(ANDROID_PADDING_RIGHT).length() > 0;
+    }
+
     /**
      * Returns whether this node's width is fill_parent.
      */
diff --git a/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule b/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
index 2221036..d3fc3d9 100644
--- a/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
+++ b/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
@@ -8,9 +8,11 @@
 // - The node is a FrameLayout
 // - The node is fill_parent in both orientation *or* it has no layout_gravity
 // - The node does not have a background nor a foreground
+// - The node does not have padding
 
 if (node.isRoot() && node.is("FrameLayout") && !node.'@android:background' &&
         !node.'@android:foreground' && ((node.isWidthFillParent() &&
-                node.isHeightFillParent()) || !node.'@android:layout_gravity')) {
+                node.isHeightFillParent()) || !node.'@android:layout_gravity') &&
+        !node.hasPadding()) {
     analysis << "The root-level <FrameLayout/> can be replaced with <merge/>"
 }
diff --git a/tools/monkeyrunner/src/Android.mk b/tools/monkeyrunner/src/Android.mk
index 576025a..fb6b9c1 100644
--- a/tools/monkeyrunner/src/Android.mk
+++ b/tools/monkeyrunner/src/Android.mk
@@ -21,9 +21,31 @@
 LOCAL_JAR_MANIFEST := ../etc/manifest.txt
 LOCAL_JAVA_LIBRARIES := \
 	ddmlib \
-	jython
+	jython \
+	xmlwriter
 
 
 LOCAL_MODULE := monkeyrunner
 
 include $(BUILD_HOST_JAVA_LIBRARY)
+
+# Build ext.jar
+# ============================================================
+
+ext_dirs := 	../../../../external/xmlwriter/src
+
+ext_src_files := $(call all-java-files-under,$(ext_dirs))
+
+# ====  the library  =========================================
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(ext_src_files)
+
+LOCAL_NO_STANDARD_LIBRARIES := true
+#LOCAL_JAVA_LIBRARIES := core
+#LOCAL_STATIC_JAVA_LIBRARIES := libgoogleclient
+
+LOCAL_MODULE := xmlwriter
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
diff --git a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java
new file mode 100644
index 0000000..efc002b
--- /dev/null
+++ b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java
@@ -0,0 +1,312 @@
+/*
+ * 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.monkeyrunner;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.jheer.XMLWriter;
+
+/**
+ *  MonkeyRecorder is a host side class that records the output of scripts that are run. 
+ *  It creates a unique directory, puts in an xml file that records each cmd and result.
+ *  It stores every screenshot in this directory.
+ *  When finished, it zips this all up.
+ *
+ *  Calling Sequence:
+ *    mr = new MonkeyRecorder(scriptName);
+ *    mr.startCommand();
+ *    [mr.addAttribute(name, value);]
+ *    ...
+ *    [mr.addInput(cmd);]
+ *    [mr.addResults(result, filename);]   // filename = "" if no screenshot
+ *    mr.endCommand();
+ *    mr.addComment(comment);
+ *    mr.startCommand();
+ *    ...
+ *    mr.endCommand();
+ *    ...
+ *    mr.close();
+ *
+ *  With MonkeyRunner this should output an xml file, <script_name>-yyyyMMdd-HH:mm:ss.xml, into the
+ *  directory out/<script_name>-yyyyMMdd-HH:mm:ss with the contents:
+ *
+ *  <?xml version="1.0" encoding='UTF-8'?>
+ *  <script_run>
+ *    script_name="filename"
+ *    monkeyRunnerVersion="0.2"
+ *    <!-- Device specific variables -->
+ *    <device_var var_name="name" var_value="value" />
+ *    <device_var name="build.display" value="opal-userdebug 1.6 DRC79 14207 test-keys"/>
+ *    ...
+ *    <!-- Script commands -->
+ *    <command>
+ *      dateTime="20090921-17:08:43"
+ *      <input cmd="Pressing: menu"/>
+ *      <response result="OK" dateTime="20090921-17:08:43"/>
+ *    </command>
+ *    ...
+ *    <command>
+ *      dateTime="20090921-17:09:44"
+ *      <input cmd="grabscreen"/>
+ *      <response result="OK" dateTime="20090921-17:09:45" screenshot="home_screen-20090921-17:09:45.png"/>
+ *    </command>
+ *    ...
+ *  </script_run>
+ *  
+ *  And then zip it up with all the screenshots in the file: <script_name>-yyyyMMdd-HH:mm:ss.zip.
+ */
+ 
+public class MonkeyRecorder {
+
+  // xml file to store output results in
+  private static String mXmlFilename;
+  private static FileWriter mXmlFile;
+  private static XMLWriter mXmlWriter;
+  
+  // unique subdirectory to put results in (screenshots and xml file)
+  private static String mDirname;
+  private static List<String> mScreenShotNames = new ArrayList<String>();
+  
+  // where we store all the results for all the script runs
+  private static final String ROOT_DIR = "out";
+  
+  // for getting the date and time in now()
+  private static final SimpleDateFormat SIMPLE_DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
+  
+  /**
+   * Create a new MonkeyRecorder that records commands and zips up screenshots for submittal
+   * 
+   * @param scriptName filepath of the monkey script we are running
+   */
+  public MonkeyRecorder(String scriptName) throws IOException {
+    // Create directory structure to store xml file, images and zips
+    File scriptFile = new File(scriptName);
+    scriptName = scriptFile.getName();  // Get rid of path
+    mDirname = ROOT_DIR + "/" + stripType(scriptName) + "-" + now();
+    new File(mDirname).mkdirs();
+    
+    // Initialize xml file
+    mXmlFilename = stampFilename(stripType(scriptName) + ".xml");
+    initXmlFile(scriptName);
+  }
+
+  // Get the current date and time in a simple string format (used for timestamping filenames)
+  private static String now() {
+    return SIMPLE_DATE_TIME_FORMAT.format(Calendar.getInstance().getTime());     
+  }
+  
+  /**
+   * Initialize the xml file writer
+   * 
+   * @param scriptName filename (not path) of the monkey script, stored as attribute in the xml file
+   */
+  private static void initXmlFile(String scriptName) throws IOException {
+    mXmlFile = new FileWriter(mDirname + "/" + mXmlFilename);
+    mXmlWriter = new XMLWriter(mXmlFile);
+    mXmlWriter.begin();
+    mXmlWriter.comment("Monkey Script Results");
+    mXmlWriter.start("script_run");
+    mXmlWriter.addAttribute("script_name", scriptName);
+  }
+  
+  /**
+   * Add a comment to the xml file.
+   * 
+   * @param comment comment to add to the xml file
+   */
+  public static void addComment(String comment) throws IOException {
+    mXmlWriter.comment(comment);
+  }
+    
+  /**
+   * Begin writing a command xml element
+   */
+  public static void startCommand() throws IOException {
+    mXmlWriter.start("command");
+    mXmlWriter.addAttribute("dateTime", now());
+  }
+  
+  /**
+   * Write a command name attribute in a command xml element.  
+   * It's add as a sinlge script command could be multiple monkey commands.
+   * 
+   * @param cmd command sent to the monkey
+   */
+  public static void addInput(String cmd)  throws IOException {
+    String name = "cmd";
+    String value = cmd;
+    mXmlWriter.tag("input", name, value);
+  }
+  
+  /**
+   * Write a response xml element in a command.  
+   * Attributes include the monkey result, datetime, and possibly screenshot filename
+   * 
+   * @param result response of the monkey to the command
+   * @param filename filename of the screen shot (or other file to be included)
+   */
+  public static void addResult(String result, String filename) throws IOException {
+    int num_args = 2;
+    String[] names = new String[3];
+    String[] values = new String[3];
+    names[0] = "result";
+    values[0] = result;
+    names[1] = "dateTime";
+    values[1] = now();
+    if (filename.length() != 0) {
+      names[2] = "screenshot";
+      values[2] = stampFilename(filename); 
+      addScreenShot(filename);
+      num_args = 3;
+    }
+    mXmlWriter.tag("response", names, values, num_args); 
+  }
+  
+  /**
+   * Add an attribut to an xml element. name="escaped_value"
+   * 
+   * @param name name of the attribute
+   * @param value value of the attribute
+   */
+  public static void addAttribute(String name, String value) throws IOException {
+    mXmlWriter.addAttribute(name, value);
+  }
+
+   /**
+   * Add an xml device variable element. name="escaped_value"
+   * 
+   * @param name name of the variable
+   * @param value value of the variable
+   */
+  public static void addDeviceVar(String name, String value) throws IOException {
+    String[] names = {"name", "value"};
+    String[] values = {name, value};
+    mXmlWriter.tag("device_var", names, values, names.length);
+  }
+ 
+  /**
+   * Move the screenshot to storage and remember you did it so it can be zipped up later.
+   * 
+   * @param filename file name of the screenshot to be stored (Not path name)
+   */
+  private static void addScreenShot(String filename) {
+    File file = new File(filename);
+    String screenShotName = stampFilename(filename);
+    file.renameTo(new File(mDirname, screenShotName));
+    mScreenShotNames.add(screenShotName);
+  }
+
+  /**
+   * Finish writing a command xml element
+   */
+  public static void endCommand() throws IOException {
+    mXmlWriter.end();
+  }
+  
+  /**
+   * Add datetime in front of filetype (the stuff after and including the last infamous '.')
+   *
+   * @param filename path of file to be stamped
+   */
+  private static String stampFilename(String filename) {
+    // 
+    int typeIndex = filename.lastIndexOf('.');
+    if (typeIndex == -1) {
+      return filename + "-" + now();
+    }  
+    return filename.substring(0, typeIndex) + "-" + now() + filename.substring(typeIndex);
+  }
+  
+  /**
+   * Strip out the file type (the stuff after and including the last infamous '.')
+   *
+   * @param filename path of file to be stripped of type information
+   */
+   private static String stripType(String filename) {
+    // 
+    int typeIndex = filename.lastIndexOf('.');
+    if (typeIndex == -1)
+      return filename;
+    return filename.substring(0, typeIndex);
+  }
+  
+   /**
+   * Add a signature element
+   *
+   * @param filename path of file to be signatured
+   */
+   private static void addMD5Signature(String filename) throws IOException {
+      String signature = "";
+      // find signature... MD5 sig = new MD5(filename); signature = sig.toString();
+      String[] names = new String[] { "type", "filename", "signature" };
+      String[] values = new String[] { "md5", filename, signature };
+      mXmlWriter.tag("Signature", names, values, values.length);
+   }
+ 
+
+  /**
+   * Close the monkeyRecorder by closing the xml file and zipping it up with the screenshots.
+   *
+   * @param filename path of file to be stripped of type information
+   */ 
+  public static void close() throws IOException {
+    // zip up xml file and screenshots into ROOT_DIR.
+    byte[] buf = new byte[1024];
+    String zipFileName = mXmlFilename + ".zip";
+    endCommand();
+    mXmlFile.close();
+    FileOutputStream zipFile = new FileOutputStream(ROOT_DIR + "/" + zipFileName);
+    ZipOutputStream out = new ZipOutputStream(zipFile);
+
+    // add the xml file
+    addFileToZip(out, mDirname + "/" + mXmlFilename, buf);
+    
+    // Add the screenshots
+    for (String filename : mScreenShotNames) {
+      addFileToZip(out, mDirname + "/" + filename, buf);
+    }
+    out.close();
+  }
+  
+  /**
+   * Helper function to zip up a file into an open zip archive.
+   *
+   * @param zip the stream of the zip archive
+   * @param filepath the filepath of the file to be added to the zip archive
+   * @param buf storage place to stage reads of file before zipping
+   */ 
+  private static void addFileToZip(ZipOutputStream zip, String filepath, byte[] buf) throws IOException {
+    FileInputStream in = new FileInputStream(filepath);
+    zip.putNextEntry(new ZipEntry(filepath));
+    int len;
+    while ((len = in.read(buf)) > 0) {
+      zip.write(buf, 0, len);
+    }
+    zip.closeEntry();
+    in.close();
+  }
+}
diff --git a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
index cbc881c..07a4739 100644
--- a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
+++ b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
@@ -30,18 +30,21 @@
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.net.InetAddress;
 import java.net.Socket;
 import java.net.UnknownHostException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.imageio.ImageIO;
 
 /**
  *  MonkeyRunner is a host side application to control a monkey instance on a
- * device. MonkeyRunner provides some useful helper functions to control the
- * device as well as various other methods to help script tests. 
+ *  device. MonkeyRunner provides some useful helper functions to control the
+ *  device as well as various other methods to help script tests. 
  */
 public class MonkeyRunner {
 
@@ -50,27 +53,46 @@
   static Socket monkeySocket = null;
 
   static IDevice monkeyDevice;
-  
+
   static BufferedReader monkeyReader;
   static BufferedWriter monkeyWriter;
+  static String monkeyResponse;
+
+  static MonkeyRecorder monkeyRecorder;
 
   static String scriptName = null;
+  
+  // Obtain a suitable logger.
+  private static Logger logger = Logger.getLogger("com.android.monkeyrunner");
 
   // delay between key events
   final static int KEY_INPUT_DELAY = 1000;
+  
+  // version of monkey runner
+  final static String monkeyRunnerVersion = "0.31";
 
-  public static void main(String[] args) {
+  // TODO: interface cmd; class xml tags; fix logger; test class/script
 
+  public static void main(String[] args) throws IOException {
+
+    // haven't figure out how to get below INFO...bad parent.  Pass -v INFO to turn on logging 
+    logger.setLevel(Level.parse("WARNING"));  
     processOptions(args);
     
+    logger.info("initAdb");
     initAdbConnection();
+    logger.info("openMonkeyConnection");
     openMonkeyConnection();
 
+    logger.info("start_script");
     start_script();
     
+    logger.info("ScriptRunner.run");
     ScriptRunner.run(scriptName);
    
+    logger.info("end_script");
     end_script();
+    logger.info("closeMonkeyConnection");
     closeMonkeyConnection();  
   }
 
@@ -166,13 +188,15 @@
     try {
       InetAddress addr = InetAddress.getByName(monkeyServer);
       monkeySocket = new Socket(addr, monkeyPort);
+      monkeyWriter = new BufferedWriter(new OutputStreamWriter(monkeySocket.getOutputStream()));
+      monkeyReader = new BufferedReader(new InputStreamReader(monkeySocket.getInputStream()));
     } catch (UnknownHostException e) {
       e.printStackTrace();
     } catch(IOException e) {
       e.printStackTrace();
     }
   }
-
+  
   /** 
    * Close tcp session with the monkey on the device
    * 
@@ -189,47 +213,59 @@
   }
 
   /** 
-   * This is a house cleaning type routine to run before starting a script. Puts
-   * the device in a known state.
+   * This is a house cleaning routine to run before starting a script. Puts
+   * the device in a known state and starts recording interesting info.
    */
-  public static void start_script() {
-    press("menu");
-    press("menu");
-    press("home");
+  public static void start_script() throws IOException {
+    press("menu", false);
+    press("menu", false);
+    press("home", false);
+    
+    // Start recording the script output, might want md5 signature of file for completeness
+    monkeyRecorder = new MonkeyRecorder(scriptName);
+
+    // Record what device and version of software we are running on
+    monkeyRecorder.addAttribute("monkeyRunnerVersion", monkeyRunnerVersion);
+    addDeviceVars();
+    monkeyRecorder.addComment("Script commands");
   }
 
-  public static void end_script() {
-    String command = "END";
-    sendMonkeyEvent(command);
+  /** 
+   * This is a house cleaning routine to run after finishing a script.
+   * Puts the monkey server in a known state and closes the recording.
+   */
+  public static void end_script() throws IOException {
+    String command = "done";
+    sendMonkeyEvent(command, false, false);
+    
+    // Stop the recording and zip up the results
+    monkeyRecorder.close();
   }
 
   /** This is a method for scripts to launch an activity on the device
    * 
    * @param name The name of the activity to launch 
    */
-  public static void launch_activity(String name) {
-    try {
-      System.out.println("Launching: " + name);
-      monkeyDevice.executeShellCommand("am start -a android.intent.action.MAIN -n " 
-          + name, new NullOutputReceiver());
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-  }
+  public static void launch_activity(String name) throws IOException {
+    System.out.println("Launching: " + name);
+    recordCommand("Launching: " + name);
+    monkeyDevice.executeShellCommand("am start -a android.intent.action.MAIN -n " 
+        + name, new NullOutputReceiver());
+    // void return, so no response given, just close the command element in the xml file.
+    monkeyRecorder.endCommand();
+   }
 
   /**
    * Grabs the current state of the screen stores it as a png
    * 
    * @param tag filename or tag descriptor of the screenshot
    */
-  public static void grabscreen(String tag) {
+  public static void grabscreen(String tag) throws IOException {
     tag += ".png";
 
     try {
       Thread.sleep(1000);
       getDeviceImage(monkeyDevice, tag, false);
-    } catch (IOException e) {
-      e.printStackTrace();
     } catch (InterruptedException e) {
     }
   }
@@ -239,9 +275,11 @@
    * 
    * @param msec msecs to sleep for
    */
-  public static void sleep(int msec) {
+  public static void sleep(int msec) throws IOException {
     try {
+      recordCommand("sleep: " + msec);
       Thread.sleep(msec);
+      recordResponse("OK");
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
@@ -253,12 +291,10 @@
    * @param x x-coordinate
    * @param y y-coordinate
    */
-  public static boolean tap(int x, int y) {
-    String command = "touch down " + x + "  " + y + "\r\n" +
-    "touch up " + x + " " + y + "\r\n";
-
-    System.out.println("Tapping: " + x + ", " + y);
-    return sendMonkeyEvent(command);
+  public static boolean tap(int x, int y) throws IOException {
+    String command = "tap " + x + " " + y;
+    boolean result = sendMonkeyEvent(command);
+    return result;
   }
 
   /** 
@@ -266,25 +302,33 @@
    * 
    * @param key key to press
    */
-  public static boolean press(String key) {
-    String command = "key down " + key + "\r\n" +
-    "key up " + key + "\r\n";
+  public static boolean press(String key) throws IOException {
+    return press(key, true);
+  }
 
-    System.out.println("Pressing: " + key);
-    return sendMonkeyEvent(command);
+  /** 
+   * Press function for scripts to call on a particular button or key
+   * 
+   * @param key key to press
+   * @param print whether to send output to user
+   */
+  private static boolean press(String key, boolean print) throws IOException {
+    String command = "press " + key;
+    boolean result = sendMonkeyEvent(command, print, true);
+    return result;
   }
 
   /**
    * dpad down function
    */
-  public static boolean down() {
+  public static boolean down() throws IOException {
     return press("dpad_down");
   }
 
   /**
    * dpad up function
    */
-  public static boolean up() {
+  public static boolean up() throws IOException {
     return press("dpad_up");
   }
 
@@ -293,69 +337,173 @@
    * 
    * @param text text to type
    */
-  public static boolean type(String text) {
-    System.out.println("Typing: " + text);
-    for (int i=0; i<text.length(); i++) {
-      String command = "key down ";
-      char c = text.charAt(i);
-      if(Character.isDigit(c)) {
-        command += "KEYCODE_" + c + "\n" + "key up KEYCODE_" + c + "\n";
-      } else {
-        command = "key down " + c + "\n" + "key up " + c + "\n";
-      }
-
-      if(!sendMonkeyEvent(command)) {
-        System.out.println("\nERROR: Key not set \n");
-      }
-
-      // lets delay a bit after each input to ensure accuracy
-      try {
-        Thread.sleep(KEY_INPUT_DELAY);
-      } catch (InterruptedException e) {
-      }
+  public static boolean type(String text) throws IOException {
+    boolean result = false;
+    // text might have line ends, which signal new monkey command, so we have to eat and reissue
+    String[] lines = text.split("[\\r\\n]+");
+    for (String line: lines) {
+      result = sendMonkeyEvent("type " + line + "\n");
     }
+    // return last result.  Should never fail..?
+    return result;
+  }
+  
+  /**
+   * Function to get a static variable from the device
+   * 
+   * @param name name of static variable to get
+   */
+  public static boolean getvar(String name) throws IOException {
+    return sendMonkeyEvent("getvar " + name + "\n");
+  }
 
-    return true;
+  /**
+   * Function to get the list of static variables from the device
+   */
+  public static boolean listvar() throws IOException {
+    return sendMonkeyEvent("listvar \n");
   }
 
   /**
    * This function is the communication bridge between the host and the device.
    * It sends monkey events and waits for responses over the adb tcp socket.
+   * This version if for all scripted events so that they get recorded and reported to user.
    * 
    * @param command the monkey command to send to the device
    */
-  private static boolean sendMonkeyEvent(String command) {
-    try {
-      monkeyWriter = new BufferedWriter(
-          new OutputStreamWriter(monkeySocket.getOutputStream()));
-      monkeyWriter.write(command);
-      monkeyWriter.flush();
+  private static boolean sendMonkeyEvent(String command) throws IOException {
+    return sendMonkeyEvent(command, true, true);
+  }
 
-      monkeyReader = new BufferedReader(
-          new InputStreamReader(monkeySocket.getInputStream()));
-      String response = monkeyReader.readLine();
+  /**
+   * This function allows the communication bridge between the host and the device
+   * to be invisible to the script for internal needs.
+   * It splits a command into monkey events and waits for responses for each over an adb tcp socket.
+   * Returns on an error, else continues and sets up last response.
+   * 
+   * @param command the monkey command to send to the device
+   * @param print whether to print out the responses to the user
+   * @param record whether to put the command in the xml file that stores test outputs
+   */
+  private static boolean sendMonkeyEvent(String command, Boolean print, Boolean record) throws IOException {
+    command = command.trim();
+    if (print)
+      System.out.println("MonkeyCommand: " + command);
+    if (record)
+      recordCommand(command);
+    logger.info("Monkey Command: " + command + ".");
+      
+    // send a single command and get the response
+    monkeyWriter.write(command + "\n");
+    monkeyWriter.flush();
+    monkeyResponse = monkeyReader.readLine();
 
-      sleep(1000);
-      System.out.println("MonkeyServer: " + response);
-      if(response.equals("OK"))
-        return true;
-      if(response.equals("ERROR"))
+    if(monkeyResponse != null) {
+      // if a command returns with a response
+      if (print)
+        System.out.println("MonkeyServer: " + monkeyResponse);
+      if (record)
+        recordResponse(monkeyResponse);
+      logger.info("Monkey Response: " + monkeyResponse + ".");
+
+      // return on error
+      if (monkeyResponse.startsWith("ERROR"))
         return false;
 
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
+      // return on ok
+      if(monkeyResponse.startsWith("OK"))
+        return true;
 
+      // return on something else?
+      return false;
+    }
+    // didn't get a response...
+    if (print)
+      System.out.println("MonkeyServer: ??no response");
+    if (record)
+      recordResponse("??no response");
+    logger.info("Monkey Response: ??no response.");
+
+    //return on no response
     return false;
   }
 
-
+  /**
+   * Record the command in the xml file
+   *
+   * @param command the command sent to the monkey server
+   */
+  private static void recordCommand(String command) throws IOException {
+    if (monkeyRecorder != null) {                       // don't record setup junk
+      monkeyRecorder.startCommand();
+      monkeyRecorder.addInput(command);
+    }
+  }
+  
+  /**
+   * Record the response in the xml file
+   *
+   * @param response the response sent by the monkey server
+   */
+  private static void recordResponse(String response) throws IOException {
+    recordResponse(response, "");
+  } 
+  
+  /**
+   * Record the response and the filename in the xml file, store the file (to be zipped up later)
+   *
+   * @param response the response sent by the monkey server
+   * @param filename the filename of a file to be time stamped, recorded in the xml file and stored
+   */
+  private static void recordResponse(String response, String filename) throws IOException {
+    if (monkeyRecorder != null) {                    // don't record setup junk
+      monkeyRecorder.addResult(response, filename);  // ignores file if filename empty
+      monkeyRecorder.endCommand();
+    }
+  }
+    
+  /**
+   * Add the device variables to the xml file in monkeyRecorder.
+   * The results get added as device_var tags in the script_run tag
+   */
+  private static void addDeviceVars() throws IOException {
+    monkeyRecorder.addComment("Device specific variables");
+    sendMonkeyEvent("listvar \n", false, false);
+    if (monkeyResponse.startsWith("OK:")) {
+      // peel off "OK:" string and get the individual var names  
+      String[] varNames = monkeyResponse.substring(3).split("\\s+");
+      // grab all the individual var values
+      for (String name: varNames) {
+        sendMonkeyEvent("getvar " + name, false, false);
+        if(monkeyResponse != null) {
+          if (monkeyResponse.startsWith("OK") ) {
+            if (monkeyResponse.length() > 2) {
+              monkeyRecorder.addDeviceVar(name, monkeyResponse.substring(3));
+            } else { 
+              // only got OK - good variable but no value
+              monkeyRecorder.addDeviceVar(name, "null");
+            }
+          } else { 
+            // error returned - couldn't get var value for name... include error return
+            monkeyRecorder.addDeviceVar(name, monkeyResponse);
+          }
+        } else { 
+          // no monkeyResponse - bad variable with no value
+          monkeyRecorder.addDeviceVar(name, "null");
+        }
+      }
+    } else {
+      // it's an error, can't find variable names...
+      monkeyRecorder.addAttribute("listvar", monkeyResponse);
+    }
+  }
+  
   /**
    * Process the command-line options
    *
    * @return Returns true if options were parsed with no apparent errors.
    */
-  public static void processOptions(String[] args) {
+  private static void processOptions(String[] args) {
     // parse command line parameters.
     int index = 0;
 
@@ -364,7 +512,7 @@
 
       if ("-s".equals(argument)) {
         if(index == args.length) {
-          printAndExit("Missing Server after -s", false);
+          printUsageAndQuit("Missing Server after -s");
         }
 
         monkeyServer = args[index++];
@@ -372,18 +520,32 @@
       } else if ("-p".equals(argument)) {
         // quick check on the next argument.
         if (index == args.length) {
-          printAndExit("Missing Server IP after -p", false /* terminate */);
+          printUsageAndQuit("Missing Server port after -p");
         }
 
         monkeyPort = Integer.parseInt(args[index++]);
-      } else {
-        // get the filepath of the script to run.
-        scriptName = argument;
 
-        // should not be any other device.
-        //if (index < args.length) {
-        //    printAndExit("Too many arguments!", false /* terminate */);
-        //}
+      } else if ("-v".equals(argument)) {
+        // quick check on the next argument.
+        if (index == args.length) {
+          printUsageAndQuit("Missing Log Level after -v");
+        }
+
+        Level level = Level.parse(args[index++]);
+        logger.setLevel(level);
+        level = logger.getLevel();
+        System.out.println("Log level set to: " + level + "(" + level.intValue() + ").");
+        System.out.println("Warning: Log levels below INFO(800) not working currently... parent issues");
+        
+      } else if (argument.startsWith("-")) {
+        // we have an unrecognized argument.
+        printUsageAndQuit("Unrecognized argument: " + argument + ".");
+
+        monkeyPort = Integer.parseInt(args[index++]);
+
+      } else {
+        // get the filepath of the script to run.  This will be the last undashed argument.
+        scriptName = argument;
       }
     } while (index < args.length);
   }
@@ -394,22 +556,29 @@
   private static void getDeviceImage(IDevice device, String filepath, boolean landscape)
   throws IOException {
     RawImage rawImage;
+    recordCommand("grabscreen");
+    System.out.println("Grabbing Screeshot: " + filepath + ".");
 
     try {
       rawImage = device.getScreenshot();
     }
     catch (IOException ioe) {
+      recordResponse("No frame buffer", "");
       printAndExit("Unable to get frame buffer: " + ioe.getMessage(), true /* terminate */);
       return;
     }
 
     // device/adb not available?
-    if (rawImage == null)
+    if (rawImage == null) {
+      recordResponse("No image", "");
       return;
-
+    }
+    
     assert rawImage.bpp == 16;
 
     BufferedImage image;
+    
+    logger.info("Raw Image - height: " + rawImage.height + ", width: " + rawImage.width);
 
     if (landscape) {
       // convert raw data to an Image
@@ -458,16 +627,20 @@
     }
 
     if (!ImageIO.write(image, "png", new File(filepath))) {
+      recordResponse("No png writer", "");
       throw new IOException("Failed to find png writer");
     }
+    recordResponse("OK", filepath);
   }
 
-  private static void printUsageAndQuit() {
+  private static void printUsageAndQuit(String message) {
     // 80 cols marker:  01234567890123456789012345678901234567890123456789012345678901234567890123456789
+    System.out.println(message);
     System.out.println("Usage: monkeyrunner [options] SCRIPT_FILE");
     System.out.println("");
     System.out.println("    -s      MonkeyServer IP Address.");
     System.out.println("    -p      MonkeyServer TCP Port.");
+    System.out.println("    -v      MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)");
     System.out.println("");
     System.out.println("");
 
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java b/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java
index 201c2fe..1c847fe 100644
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java
+++ b/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java
@@ -43,7 +43,6 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import javax.xml.xpath.XPath;
@@ -994,13 +993,16 @@
         // get the list of possible hardware properties
         File hardwareDefs = new File (mOsSdkFolder + File.separator +
                 SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI);
-        List<HardwareProperty> list = HardwareProperties.parseHardwareDefinitions(hardwareDefs,
-                null /*sdkLog*/);
+        Map<String, HardwareProperty> hwMap = HardwareProperties.parseHardwareDefinitions(
+                hardwareDefs, null /*sdkLog*/);
 
         HashMap<String, String> map = new HashMap<String, String>();
 
-        for (int i = 0 ; i < list.size() ;) {
-            HardwareProperty property = list.get(i);
+        // we just want to loop on the HardwareProperties
+        HardwareProperty[] hwProperties = hwMap.values().toArray(
+                new HardwareProperty[hwMap.size()]);
+        for (int i = 0 ; i < hwProperties.length ;) {
+            HardwareProperty property = hwProperties[i];
 
             String description = property.getDescription();
             if (description != null) {
diff --git a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/HardwareProperties.java b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/HardwareProperties.java
index 81acfef..77142b1 100644
--- a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/HardwareProperties.java
+++ b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/HardwareProperties.java
@@ -24,43 +24,52 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class HardwareProperties {
     private final static Pattern PATTERN_PROP = Pattern.compile(
     "^([a-zA-Z0-9._-]+)\\s*=\\s*(.*)\\s*$");
-    
+
     private final static String HW_PROP_NAME = "name";
     private final static String HW_PROP_TYPE = "type";
     private final static String HW_PROP_DEFAULT = "default";
     private final static String HW_PROP_ABSTRACT = "abstract";
     private final static String HW_PROP_DESC = "description";
-    
+
+    private final static String BOOLEAN_YES = "yes";
+    private final static String BOOLEAN_NO = "no";
+    public final static String[] BOOLEAN_VALUES = new String[] { BOOLEAN_YES, BOOLEAN_NO };
+    public final static Pattern DISKSIZE_PATTERN = Pattern.compile("\\d+[MK]B");
+
     public enum ValueType {
         INTEGER("integer"),
         BOOLEAN("boolean"),
         DISKSIZE("diskSize");
-        
+
         private String mValue;
 
         ValueType(String value) {
             mValue = value;
         }
-        
+
+        public String getValue() {
+            return mValue;
+        }
+
         public static ValueType getEnum(String value) {
             for (ValueType type : values()) {
                 if (type.mValue.equals(value)) {
                     return type;
                 }
             }
-            
+
             return null;
         }
     }
-    
+
     public static final class HardwareProperty {
         private String mName;
         private ValueType mType;
@@ -68,40 +77,40 @@
         private String mDefault;
         private String mAbstract;
         private String mDescription;
-        
+
         public String getName() {
             return mName;
         }
-        
+
         public ValueType getType() {
             return mType;
         }
-        
+
         public String getDefault() {
             return mDefault;
         }
-        
+
         public String getAbstract() {
             return mAbstract;
         }
-        
+
         public String getDescription() {
             return mDescription;
         }
     }
-    
+
     /**
      * Parses the hardware definition file.
      * @param file the property file to parse
      * @param log the ISdkLog object receiving warning/error from the parsing.
      * @return the map of (key,value) pairs, or null if the parsing failed.
      */
-    public static List<HardwareProperty> parseHardwareDefinitions(File file, ISdkLog log) {
+    public static Map<String, HardwareProperty> parseHardwareDefinitions(File file, ISdkLog log) {
         try {
             FileInputStream fis = new FileInputStream(file);
             BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
 
-            List<HardwareProperty> map = new ArrayList<HardwareProperty>();
+            Map<String, HardwareProperty> map = new HashMap<String, HardwareProperty>();
 
             String line = null;
             HardwareProperty prop = null;
@@ -115,15 +124,15 @@
                         if (HW_PROP_NAME.equals(valueName)) {
                             prop = new HardwareProperty();
                             prop.mName = value;
-                            map.add(prop);
+                            map.put(prop.mName, prop);
                         }
-                        
+
                         if (prop == null) {
                             log.warning("Error parsing '%1$s': missing '%2$s'",
                                     file.getAbsolutePath(), HW_PROP_NAME);
                             return null;
                         }
-                        
+
                         if (HW_PROP_TYPE.equals(valueName)) {
                             prop.mType = ValueType.getEnum(value);
                         } else if (HW_PROP_DEFAULT.equals(valueName)) {
@@ -140,7 +149,7 @@
                     }
                 }
             }
-            
+
             return map;
         } catch (FileNotFoundException e) {
             // this should not happen since we usually test the file existence before
@@ -156,4 +165,16 @@
         return null;
     }
 
+    /**
+     * Returns the index of <var>value</var> in {@link #BOOLEAN_VALUES}.
+     */
+    public static int getBooleanValueIndex(String value) {
+        if (BOOLEAN_YES.equals(value)) {
+            return 0;
+        } else if (BOOLEAN_NO.equals(value)) {
+            return 1;
+        }
+
+        return -1;
+    }
 }
diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
index fbcf95a..fbe11ef 100644
--- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
+++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdCreationDialog.java
@@ -19,14 +19,32 @@
 import com.android.prefs.AndroidLocation;
 import com.android.prefs.AndroidLocation.AndroidLocationException;
 import com.android.sdklib.IAndroidTarget;
+import com.android.sdklib.SdkConstants;
 import com.android.sdklib.SdkManager;
 import com.android.sdklib.internal.avd.AvdManager;
+import com.android.sdklib.internal.avd.HardwareProperties;
 import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
+import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty;
 import com.android.sdkuilib.internal.repository.icons.ImageFactory;
 import com.android.sdkuilib.internal.widgets.AvdSelector.SdkLog;
+import com.android.sdkuilib.ui.GridDialog;
 
-import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.jface.window.Window;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -45,26 +63,36 @@
 import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.TreeMap;
+import java.util.Map.Entry;
 
 /**
  * AVD creator dialog.
  *
  * TODO:
- * - support custom hardware properties
  * - use SdkTargetSelector instead of Combo
  * - tooltips on widgets.
  *
  */
-final class AvdCreationDialog extends Dialog {
+final class AvdCreationDialog extends GridDialog {
 
     private final AvdManager mAvdManager;
     private final TreeMap<String, IAndroidTarget> mCurrentTargets =
         new TreeMap<String, IAndroidTarget>();
 
+    private final Map<String, HardwareProperty> mHardwareMap;
+    private final Map<String, String> mProperties = new HashMap<String, String>();
+    // a list of user-edited properties.
+    private final ArrayList<String> mEditedProperties = new ArrayList<String>();
+
     private Text mAvdName;
     private Combo mTargetCombo;
 
@@ -76,17 +104,22 @@
     private Button mBrowseSdCard;
     private Button mSdCardFileRadio;
 
+    private Button mSkinListRadio;
     private Combo mSkinCombo;
+
+    private Button mSkinSizeRadio;
+    private Text mSkinSizeWidth;
+    private Text mSkinSizeHeight;
+
+    private TableViewer mHardwareViewer;
+    private Button mDeleteHardwareProp;
+
     private Button mForceCreation;
     private Button mOkButton;
     private Label mStatusIcon;
     private Label mStatusLabel;
     private Composite mStatusComposite;
     private final ImageFactory mImageFactory;
-    private Button mSkinListRadio;
-    private Button mSkinSizeRadio;
-    private Text mSkinSizeWidth;
-    private Text mSkinSizeHeight;
 
     /**
      * {@link VerifyListener} for {@link Text} widgets that should only contains numbers.
@@ -140,9 +173,14 @@
 
     protected AvdCreationDialog(Shell parentShell, AvdManager avdManager,
             ImageFactory imageFactory) {
-        super(parentShell);
+        super(parentShell, 2, false);
         mAvdManager = avdManager;
         mImageFactory = imageFactory;
+
+        File hardwareDefs = new File (avdManager.getSdkManager().getLocation() + File.separator +
+                SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI);
+        mHardwareMap = HardwareProperties.parseHardwareDefinitions(
+                hardwareDefs, null /*sdkLog*/);
     }
 
     @Override
@@ -168,31 +206,21 @@
     }
 
     @Override
-    protected Control createDialogArea(Composite parent) {
+    public void createDialogContent(final Composite parent) {
         GridData gd;
-        final int groupIndent = 30;
+        GridLayout gl;
 
-        Composite top = new Composite(parent, SWT.NONE);
-        GridLayout layout = new GridLayout(2, false);
-        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
-        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
-        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
-        layout.horizontalSpacing = convertHorizontalDLUsToPixels(
-                IDialogConstants.HORIZONTAL_SPACING);
-        top.setLayout(layout);
-        top.setLayoutData(new GridData(GridData.FILL_BOTH));
-
-        Label label = new Label(top, SWT.NONE);
+        Label label = new Label(parent, SWT.NONE);
         label.setText("Name:");
 
-        mAvdName = new Text(top, SWT.BORDER);
+        mAvdName = new Text(parent, SWT.BORDER);
         mAvdName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         mAvdName.addModifyListener(new CreateNameModifyListener());
 
-        label = new Label(top, SWT.NONE);
+        label = new Label(parent, SWT.NONE);
         label.setText("Target:");
 
-        mTargetCombo = new Combo(top, SWT.READ_ONLY | SWT.DROP_DOWN);
+        mTargetCombo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
         mTargetCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         mTargetCombo.addSelectionListener(new SelectionAdapter() {
             @Override
@@ -204,15 +232,13 @@
         });
 
         // --- sd card group
-        label = new Label(top, SWT.NONE);
+        label = new Label(parent, SWT.NONE);
         label.setText("SD Card:");
-        label.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
-        gd.horizontalSpan = 2;
+        label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING,
+                false, false));
 
-        final Group sdCardGroup = new Group(top, SWT.NONE);
-        sdCardGroup.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
-        gd.horizontalIndent = groupIndent;
-        gd.horizontalSpan = 2;
+        final Group sdCardGroup = new Group(parent, SWT.NONE);
+        sdCardGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         sdCardGroup.setLayout(new GridLayout(3, false));
 
         mSdCardSizeRadio = new Button(sdCardGroup, SWT.RADIO);
@@ -233,8 +259,8 @@
         mSdCardSize.addVerifyListener(mDigitVerifier);
 
         mSdCardSizeCombo = new Combo(sdCardGroup, SWT.DROP_DOWN | SWT.READ_ONLY);
-        mSdCardSizeCombo.add("K");
-        mSdCardSizeCombo.add("M");
+        mSdCardSizeCombo.add("KiB");
+        mSdCardSizeCombo.add("MiB");
         mSdCardSizeCombo.select(1);
 
         mSdCardFileRadio = new Button(sdCardGroup, SWT.RADIO);
@@ -258,15 +284,13 @@
         enableSdCardWidgets(true);
 
         // --- skin group
-        label = new Label(top, SWT.NONE);
+        label = new Label(parent, SWT.NONE);
         label.setText("Skin:");
-        label.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
-        gd.horizontalSpan = 2;
+        label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING,
+                false, false));
 
-        final Group skinGroup = new Group(top, SWT.NONE);
-        skinGroup.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
-        gd.horizontalIndent = groupIndent;
-        gd.horizontalSpan = 2;
+        final Group skinGroup = new Group(parent, SWT.NONE);
+        skinGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         skinGroup.setLayout(new GridLayout(4, false));
 
         mSkinListRadio = new Button(skinGroup, SWT.RADIO);
@@ -283,6 +307,13 @@
         mSkinCombo = new Combo(skinGroup, SWT.READ_ONLY | SWT.DROP_DOWN);
         mSkinCombo.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
         gd.horizontalSpan = 3;
+        mSkinCombo.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent arg0) {
+                // get the skin info
+                loadSkin();
+            }
+        });
 
         mSkinSizeRadio = new Button(skinGroup, SWT.RADIO);
         mSkinSizeRadio.setText("Size:");
@@ -302,9 +333,60 @@
         mSkinListRadio.setSelection(true);
         enableSkinWidgets(true);
 
-        // --- end skin group
+        // --- hardware group
+        label = new Label(parent, SWT.NONE);
+        label.setText("Hardware:");
+        label.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING,
+                false, false));
 
-        mForceCreation = new Button(top, SWT.CHECK);
+        final Group hwGroup = new Group(parent, SWT.NONE);
+        hwGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+        hwGroup.setLayout(new GridLayout(2, false));
+
+        createHardwareTable(hwGroup);
+
+        // composite for the side buttons
+        Composite hwButtons = new Composite(hwGroup, SWT.NONE);
+        hwButtons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+        hwButtons.setLayout(gl = new GridLayout(1, false));
+        gl.marginHeight = gl.marginWidth = 0;
+
+        Button b = new Button(hwButtons, SWT.PUSH | SWT.FLAT);
+        b.setText("New...");
+        b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+        b.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent event) {
+                HardwarePropertyChooser dialog = new HardwarePropertyChooser(parent.getShell(),
+                        mHardwareMap, mProperties.keySet());
+                if (dialog.open() == Window.OK) {
+                    HardwareProperty choice = dialog.getProperty();
+                    if (choice != null) {
+                        mProperties.put(choice.getName(), choice.getDefault());
+                        mHardwareViewer.refresh();
+                    }
+                }
+            }
+        });
+        mDeleteHardwareProp = new Button(hwButtons, SWT.PUSH | SWT.FLAT);
+        mDeleteHardwareProp.setText("Delete");
+        mDeleteHardwareProp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+        mDeleteHardwareProp.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent arg0) {
+                ISelection selection = mHardwareViewer.getSelection();
+                if (selection instanceof IStructuredSelection) {
+                    String hwName = (String)((IStructuredSelection)selection).getFirstElement();
+                    mProperties.remove(hwName);
+                    mHardwareViewer.refresh();
+                }
+            }
+        });
+        mDeleteHardwareProp.setEnabled(false);
+
+        // --- end hardware group
+
+        mForceCreation = new Button(parent, SWT.CHECK);
         mForceCreation.setText("Force create");
         mForceCreation.setToolTipText("Select this to override any existing AVD");
         mForceCreation.setLayoutData(new GridData(GridData.END, GridData.CENTER,
@@ -313,14 +395,13 @@
         mForceCreation.addSelectionListener(validateListener);
 
         // add a separator to separate from the ok/cancel button
-        label = new Label(top, SWT.SEPARATOR | SWT.HORIZONTAL);
+        label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
         label.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
 
         // add stuff for the error display
-        mStatusComposite = new Composite(top, SWT.NONE);
+        mStatusComposite = new Composite(parent, SWT.NONE);
         mStatusComposite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
                 true, false, 3, 1));
-        GridLayout gl;
         mStatusComposite.setLayout(gl = new GridLayout(2, false));
         gl.marginHeight = gl.marginWidth = 0;
 
@@ -332,9 +413,141 @@
         mStatusLabel.setText(" \n "); //$NON-NLS-1$
 
         reloadTargetCombo();
+    }
 
-        applyDialogFont(top);
-        return top;
+    /**
+     * Creates the UI for the hardware properties table.
+     * This creates the {@link Table}, and several viewers ({@link TableViewer},
+     * {@link TableViewerColumn}) and adds edit support for the 2nd column
+     */
+    private void createHardwareTable(Composite parent) {
+        final Table hardwareTable = new Table(parent, SWT.SINGLE | SWT.FULL_SELECTION);
+        GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+        gd.widthHint = 200;
+        gd.heightHint = 100;
+        hardwareTable.setLayoutData(gd);
+        hardwareTable.setHeaderVisible(true);
+        hardwareTable.setLinesVisible(true);
+
+        // -- Table viewer
+        mHardwareViewer = new TableViewer(hardwareTable);
+        mHardwareViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+            public void selectionChanged(SelectionChangedEvent event) {
+                // it's a single selection mode, we can just access the selection index
+                // from the table directly.
+                mDeleteHardwareProp.setEnabled(hardwareTable.getSelectionIndex() != -1);
+            }
+        });
+
+        // only a content provider. Use viewers per column below (for editing support)
+        mHardwareViewer.setContentProvider(new IStructuredContentProvider() {
+            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                // we can just ignore this. we just use mProperties directly.
+            }
+
+            public Object[] getElements(Object arg0) {
+                return mProperties.keySet().toArray();
+            }
+
+            public void dispose() {
+                // pass
+            }
+        });
+
+        // -- column 1: prop abstract name
+        TableColumn col1 = new TableColumn(hardwareTable, SWT.LEFT);
+        col1.setText("Property");
+        col1.setWidth(150);
+        TableViewerColumn tvc1 = new TableViewerColumn(mHardwareViewer, col1);
+        tvc1.setLabelProvider(new CellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                HardwareProperty prop = mHardwareMap.get(cell.getElement());
+                cell.setText(prop != null ? prop.getAbstract() : "");
+            }
+        });
+
+        // -- column 2: prop value
+        TableColumn col2 = new TableColumn(hardwareTable, SWT.LEFT);
+        col2.setText("Value");
+        col2.setWidth(50);
+        TableViewerColumn tvc2 = new TableViewerColumn(mHardwareViewer, col2);
+        tvc2.setLabelProvider(new CellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                String value = mProperties.get(cell.getElement());
+                cell.setText(value != null ? value : "");
+            }
+        });
+
+        // add editing support to the 2nd column
+        tvc2.setEditingSupport(new EditingSupport(mHardwareViewer) {
+            @Override
+            protected void setValue(Object element, Object value) {
+                String hardwareName = (String)element;
+                HardwareProperty property = mHardwareMap.get(hardwareName);
+                switch (property.getType()) {
+                    case INTEGER:
+                        mProperties.put((String)element, (String)value);
+                        break;
+                    case DISKSIZE:
+                        if (HardwareProperties.DISKSIZE_PATTERN.matcher((String)value).matches()) {
+                            mProperties.put((String)element, (String)value);
+                        }
+                        break;
+                    case BOOLEAN:
+                        int index = (Integer)value;
+                        mProperties.put((String)element, HardwareProperties.BOOLEAN_VALUES[index]);
+                        break;
+                }
+                mHardwareViewer.refresh(element);
+            }
+
+            @Override
+            protected Object getValue(Object element) {
+                String hardwareName = (String)element;
+                HardwareProperty property = mHardwareMap.get(hardwareName);
+                String value = mProperties.get(hardwareName);
+                switch (property.getType()) {
+                    case INTEGER:
+                        // intended fall-through.
+                    case DISKSIZE:
+                        return value;
+                    case BOOLEAN:
+                        return HardwareProperties.getBooleanValueIndex(value);
+                }
+
+                return null;
+            }
+
+            @Override
+            protected CellEditor getCellEditor(Object element) {
+                String hardwareName = (String)element;
+                HardwareProperty property = mHardwareMap.get(hardwareName);
+                switch (property.getType()) {
+                    // TODO: custom TextCellEditor that restrict input.
+                    case INTEGER:
+                        // intended fall-through.
+                    case DISKSIZE:
+                        return new TextCellEditor(hardwareTable);
+                    case BOOLEAN:
+                        return new ComboBoxCellEditor(hardwareTable,
+                                HardwareProperties.BOOLEAN_VALUES,
+                                SWT.READ_ONLY | SWT.DROP_DOWN);
+                }
+                return null;
+            }
+
+            @Override
+            protected boolean canEdit(Object element) {
+                String hardwareName = (String)element;
+                HardwareProperty property = mHardwareMap.get(hardwareName);
+                return property != null;
+            }
+        });
+
+
+        mHardwareViewer.setInput(mProperties);
     }
 
     @Override
@@ -469,6 +682,7 @@
                     mSkinCombo.select(index);
                 } else {
                     mSkinCombo.select(0);  // default
+                    loadSkin();
                 }
             }
         }
@@ -553,6 +767,78 @@
         mStatusComposite.pack(true);
     }
 
+    private void loadSkin() {
+        int targetIndex = mTargetCombo.getSelectionIndex();
+        if (targetIndex < 0) {
+            return;
+        }
+
+        // resolve the target.
+        String targetName = mTargetCombo.getItem(targetIndex);
+        IAndroidTarget target = mCurrentTargets.get(targetName);
+        if (target == null) {
+            return;
+        }
+
+        // get the skin name
+        String skinName = null;
+        int skinIndex = mSkinCombo.getSelectionIndex();
+        if (skinIndex < 0) {
+            return;
+        } else if (skinIndex == 0) { // default skin for the target
+            skinName = target.getDefaultSkin();
+        } else {
+            skinName = mSkinCombo.getItem(skinIndex);
+        }
+
+        // load the skin properties
+        String path = target.getPath(IAndroidTarget.SKINS);
+        File skin = new File(path, skinName);
+        if (skin.isDirectory() == false && target.isPlatform() == false) {
+            // it's possible the skin is in the parent target
+            path = target.getParent().getPath(IAndroidTarget.SKINS);
+            skin = new File(path, skinName);
+        }
+
+        if (skin.isDirectory() == false) {
+            return;
+        }
+
+        // now get the hardware.ini from the add-on (if applicable) and from the skin
+        // (if applicable)
+        HashMap<String, String> hardwareValues = new HashMap<String, String>();
+        if (target.isPlatform() == false) {
+            File targetHardwareFile = new File(target.getLocation(), AvdManager.HARDWARE_INI);
+            if (targetHardwareFile.isFile()) {
+                Map<String, String> targetHardwareConfig = SdkManager.parsePropertyFile(
+                        targetHardwareFile, null /*log*/);
+                if (targetHardwareConfig != null) {
+                    hardwareValues.putAll(targetHardwareConfig);
+                }
+            }
+        }
+
+        // from the skin
+        File skinHardwareFile = new File(skin, AvdManager.HARDWARE_INI);
+        if (skinHardwareFile.isFile()) {
+            Map<String, String> skinHardwareConfig = SdkManager.parsePropertyFile(
+                    skinHardwareFile, null /*log*/);
+            if (skinHardwareConfig != null) {
+                hardwareValues.putAll(skinHardwareConfig);
+            }
+        }
+
+        // now set those values in the list of properties for the AVD.
+        // We just check that none of those properties have been edited by the user yet.
+        for (Entry<String, String> entry : hardwareValues.entrySet()) {
+            if (mEditedProperties.contains(entry.getKey()) == false) {
+                mProperties.put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        mHardwareViewer.refresh();
+    }
+
     /**
      * Creates an AVD from the values in the UI. Called when the user presses the OK button.
      */
@@ -633,7 +919,7 @@
                 target,
                 skinName,
                 sdName,
-                null, // hardwareConfig,
+                mProperties,
                 force,
                 log);
 
diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
index d96534b..abc36fd 100644
--- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
+++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/AvdStartDialog.java
@@ -19,6 +19,7 @@
 import com.android.sdklib.internal.avd.AvdManager;
 import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
 import com.android.sdkuilib.internal.repository.SettingsController;
+import com.android.sdkuilib.ui.GridDialog;
 
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
@@ -60,7 +61,7 @@
  * Values are stored (in the class as static field) to be reused while the app is still running.
  * The Monitor dpi is stored in the settings if availabe.
  */
-final class AvdStartDialog extends Dialog {
+final class AvdStartDialog extends GridDialog {
     // static field to reuse values during the same session.
     private static boolean sWipeData = false;
     private static int sMonitorDpi = 72; // used if there's no setting controller.
@@ -86,7 +87,7 @@
 
     AvdStartDialog(Shell parentShell, AvdInfo avd, String sdkLocation,
             SettingsController settingsController) {
-        super(parentShell);
+        super(parentShell, 2, false);
         mAvd = avd;
         mSdkLocation = sdkLocation;
         mSettingsController = settingsController;
@@ -112,42 +113,31 @@
     }
 
     @Override
-    protected Control createDialogArea(final Composite parent) {
+    public void createDialogContent(final Composite parent) {
         GridData gd;
 
-        // create a composite with standard margins and spacing
-        Composite composite = new Composite(parent, SWT.NONE);
-        GridLayout layout = new GridLayout(2, false);
-        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
-        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
-        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
-        layout.horizontalSpacing = convertHorizontalDLUsToPixels(
-                IDialogConstants.HORIZONTAL_SPACING);
-        composite.setLayout(layout);
-        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
-        Label l = new Label(composite, SWT.NONE);
+        Label l = new Label(parent, SWT.NONE);
         l.setText("Skin:");
 
-        l = new Label(composite, SWT.NONE);
+        l = new Label(parent, SWT.NONE);
         l.setText(mSkinDisplay);
         l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 
-        l = new Label(composite, SWT.NONE);
+        l = new Label(parent, SWT.NONE);
         l.setText("Density:");
 
-        l = new Label(composite, SWT.NONE);
+        l = new Label(parent, SWT.NONE);
         l.setText(getDensityText());
         l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
 
-        mScaleButton = new Button(composite, SWT.CHECK);
+        mScaleButton = new Button(parent, SWT.CHECK);
         mScaleButton.setText("Scale display to real size");
         mScaleButton.setEnabled(mEnableScaling);
         boolean defaultState = mEnableScaling && sSkinScaling.get(mAvd.getName()) != null;
         mScaleButton.setSelection(defaultState);
         mScaleButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
         gd.horizontalSpan = 2;
-        final Group scaleGroup = new Group(composite, SWT.NONE);
+        final Group scaleGroup = new Group(parent, SWT.NONE);
         scaleGroup.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
         gd.horizontalIndent = 30;
         gd.horizontalSpan = 2;
@@ -229,7 +219,7 @@
             }
         });
 
-        final Button wipeButton = new Button(composite, SWT.CHECK);
+        final Button wipeButton = new Button(parent, SWT.CHECK);
         wipeButton.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
         gd.horizontalSpan = 2;
         wipeButton.setText("Wipe user data");
@@ -241,18 +231,14 @@
             }
         });
 
-        l = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+        l = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
         l.setLayoutData(gd = new GridData(GridData.FILL_HORIZONTAL));
         gd.horizontalSpan = 2;
 
-        applyDialogFont(composite);
-
         // if the scaling is enabled by default, we must initialize the value of mScale
         if (defaultState) {
             onScaleChange();
         }
-
-        return composite;
     }
 
     @Override
diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/HardwarePropertyChooser.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/HardwarePropertyChooser.java
new file mode 100644
index 0000000..5184442
--- /dev/null
+++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/HardwarePropertyChooser.java
@@ -0,0 +1,119 @@
+/*
+ * 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.sdkuilib.internal.widgets;
+
+import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty;
+import com.android.sdkuilib.ui.GridDialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * Dialog to choose a hardware property
+ */
+class HardwarePropertyChooser extends GridDialog {
+
+    private final Map<String, HardwareProperty> mProperties;
+    private final Collection<String> mExceptProperties;
+    private HardwareProperty mChosenProperty;
+    private Label mTypeLabel;
+    private Label mDescriptionLabel;
+
+    HardwarePropertyChooser(Shell parentShell, Map<String, HardwareProperty> properties,
+            Collection<String> exceptProperties) {
+        super(parentShell, 2, false);
+        mProperties = properties;
+        mExceptProperties = exceptProperties;
+    }
+
+    public HardwareProperty getProperty() {
+        return mChosenProperty;
+    }
+
+    @Override
+    public void createDialogContent(Composite parent) {
+        Label l = new Label(parent, SWT.NONE);
+        l.setText("Property:");
+
+        final Combo c = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
+        // simple list for index->name resolution.
+        final ArrayList<String> indexToName = new ArrayList<String>();
+        for (Entry<String, HardwareProperty> entry : mProperties.entrySet()) {
+            if (mExceptProperties.contains(entry.getKey()) == false) {
+                c.add(entry.getValue().getAbstract());
+                indexToName.add(entry.getKey());
+            }
+        }
+        boolean hasValues = true;
+        if (indexToName.size() == 0) {
+            hasValues = false;
+            c.add("No properties");
+            c.select(0);
+            c.setEnabled(false);
+        }
+
+        c.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent event) {
+                int index = c.getSelectionIndex();
+                String name = indexToName.get(index);
+                processSelection(name, true /* pack */);
+            }
+        });
+
+        l = new Label(parent, SWT.NONE);
+        l.setText("Type:");
+
+        mTypeLabel = new Label(parent, SWT.NONE);
+
+        l = new Label(parent, SWT.NONE);
+        l.setText("Description:");
+
+        mDescriptionLabel = new Label(parent, SWT.NONE);
+
+        if (hasValues) {
+            c.select(0);
+            processSelection(indexToName.get(0), false /* pack */);
+        }
+    }
+
+    private void processSelection(String name, boolean pack) {
+        mChosenProperty = mProperties.get(name);
+        mTypeLabel.setText(mChosenProperty.getType().getValue());
+        String desc = mChosenProperty.getDescription();
+        if (desc != null) {
+            mDescriptionLabel.setText(mChosenProperty.getDescription());
+        } else {
+            mDescriptionLabel.setText("N/A");
+        }
+
+        if (pack) {
+            getShell().pack();
+        }
+    }
+
+}
diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/ResolutionChooserDialog.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/ResolutionChooserDialog.java
index 94ed3b9..60888e6 100644
--- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/ResolutionChooserDialog.java
+++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/widgets/ResolutionChooserDialog.java
@@ -16,14 +16,13 @@
 
 package com.android.sdkuilib.internal.widgets;
 
-import org.eclipse.jface.dialogs.Dialog;
+import com.android.sdkuilib.ui.GridDialog;
+
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
@@ -40,7 +39,7 @@
  * After the dialog as returned, one can query {@link #getDensity()} to get the chosen monitor
  * pixel density.
  */
-class ResolutionChooserDialog extends Dialog {
+class ResolutionChooserDialog extends GridDialog {
     public final static float[] MONITOR_SIZES = new float[] {
             13.3f, 14, 15.4f, 15.6f, 17, 19, 20, 21, 24, 30,
     };
@@ -54,7 +53,7 @@
     private int mMonitorIndex = 0;
 
     ResolutionChooserDialog(Shell parentShell) {
-        super(parentShell);
+        super(parentShell, 2, false);
     }
 
     /**
@@ -84,22 +83,11 @@
     }
 
     @Override
-    protected Control createDialogArea(Composite parent) {
-        // create a composite with standard margins and spacing
-        Composite composite = new Composite(parent, SWT.NONE);
-        GridLayout layout = new GridLayout(2, false);
-        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
-        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
-        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
-        layout.horizontalSpacing = convertHorizontalDLUsToPixels(
-                IDialogConstants.HORIZONTAL_SPACING);
-        composite.setLayout(layout);
-        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
-        Label l = new Label(composite, SWT.NONE);
+    public void createDialogContent(Composite parent) {
+        Label l = new Label(parent, SWT.NONE);
         l.setText("Screen Size:");
 
-        mScreenSizeCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+        mScreenSizeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
         for (float size : MONITOR_SIZES) {
             if (Math.round(size) == size) {
                 mScreenSizeCombo.add(String.format("%.0f\"", size));
@@ -115,10 +103,10 @@
             }
         });
 
-        l = new Label(composite, SWT.NONE);
+        l = new Label(parent, SWT.NONE);
         l.setText("Resolution:");
 
-        mMonitorCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
+        mMonitorCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
         mMonitors = parent.getDisplay().getMonitors();
         for (Monitor m : mMonitors) {
             Rectangle r = m.getBounds();
@@ -131,8 +119,5 @@
                 mMonitorIndex = mMonitorCombo.getSelectionIndex();
             }
         });
-
-        applyDialogFont(composite);
-        return composite;
     }
 }
diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/GridDialog.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/GridDialog.java
new file mode 100644
index 0000000..8329fd6
--- /dev/null
+++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/ui/GridDialog.java
@@ -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.
+ */
+
+package com.android.sdkuilib.ui;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * jface-based dialog that properly sets up a {@link GridLayout} top composite with the proper
+ * margin.
+ *
+ * Implementing dialog must create the content of the dialog in
+ * {@link #createDialogContent(Composite)}.
+ *
+ */
+public abstract class GridDialog extends Dialog {
+
+    private final int mNumColumns;
+    private final boolean mMakeColumnsEqualWidth;
+
+    /**
+     * Creates the dialog
+     * @param parentShell the parent {@link Shell}.
+     * @param numColumns the number of columns in the grid
+     * @param makeColumnsEqualWidth whether or not the columns will have equal width
+     */
+    public GridDialog(Shell parentShell, int numColumns, boolean makeColumnsEqualWidth) {
+        super(parentShell);
+        mNumColumns = numColumns;
+        mMakeColumnsEqualWidth = makeColumnsEqualWidth;
+    }
+
+    /**
+     * Creates the content of the dialog. The <var>parent</var> composite is a {@link GridLayout}
+     * created with the <var>numColumn</var> and <var>makeColumnsEqualWidth</var> parameters
+     * passed to {@link #GridDialog(Shell, int, boolean)}.
+     * @param parent the parent composite.
+     */
+    public abstract void createDialogContent(Composite parent);
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite top = new Composite(parent, SWT.NONE);
+        GridLayout layout = new GridLayout(mNumColumns, mMakeColumnsEqualWidth);
+        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
+        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
+        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
+        layout.horizontalSpacing = convertHorizontalDLUsToPixels(
+                IDialogConstants.HORIZONTAL_SPACING);
+        top.setLayout(layout);
+        top.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        createDialogContent(top);
+
+        applyDialogFont(top);
+        return top;
+    }
+}