manual merge of 367910fc, don't build ota or update packages for sdk or sim

Merge commit '367910fc'
diff --git a/buildspec.mk.default b/buildspec.mk.default
index 861bb0d..6fd93da 100644
--- a/buildspec.mk.default
+++ b/buildspec.mk.default
@@ -88,10 +88,16 @@
 #NO_FALLBACK_FONT:=true
 endif
 
-# To enabled instrumentation in webcore based apps like gmail and
+# To enable instrumentation in webcore based apps like gmail and
 # the browser, define WEBCORE_INSTRUMENTATION:=true
+ifndef WEBCORE_INSTRUMENTATION
 #WEBCORE_INSTRUMENTATION:=true
-#endif
+endif
+
+# To enable SVG in webcore define ENABLE_SVG:=true
+ifndef ENABLE_SVG
+#ENABLE_SVG:=true
+endif
 
 # when the build system changes such that this file must be updated, this
 # variable will be changed.  After you have modified this file with the new
diff --git a/cleanspec.mk b/cleanspec.mk
index 4cf3f59..f0f4049 100644
--- a/cleanspec.mk
+++ b/cleanspec.mk
@@ -76,13 +76,35 @@
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/com.android.inputmethod.pinyin.lib_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/PinyinIMEGoogleService_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/telephony)
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libwebcore_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj)
 $(call add-clean-step, rm -f $(PRODUCT_OUT)/system/bin/tcpdump)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/location)
 
 $(call add-clean-step, rm -rf $(OUT_DIR)/product/*/obj/SHARED_LIBRARIES/lib?camera_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/product/*/obj/STATIC_LIBRARIES/lib?camera_intermediates)
-$(call add-clean-step, rm -rf $(OUT_DIR)/target/product/*/obj/SHARED_LIBRARIES/libwebcore_intermediates)
+
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/bluetooth/*)
+$(call add-clean-step, rm -rf $(OUT_DIR)/host/common/obj/JAVA_LIBRARIES/layoutlib_intermediates/classes/android/bluetooth/*)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/SHARED_LIBRARIES/libbluetooth_intermediates/*)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/lib/libhcid.so)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/system/lib/libhcid.so)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/symbols/system/lib/libhcid.so)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/EXECUTABLES/hcid_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/system/bin/hcid)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/symbols/system/bin/hcid)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/EXECUTABLES/passkey-agent_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/system/xbin/passkey-agent)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/symbols/system/bin/passkey-agent)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/EXECUTABLES/auth-agent_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/system/xbin/auth-agent)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/symbols/system/bin/auth-agent)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/STATIC_LIBRARIES/libeglib_static_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/STATIC_LIBRARIES/libgdbus_static_intermediates/*)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/STATIC_LIBRARIES/libbluez-utils-common-static_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/obj/EXECUTABLES/hcidump_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/system/bin/hcidump)
+$(call add-clean-step, rm -rf $(PRODUCT_DIR)/symbols/system/bin/hcidump)
 
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
diff --git a/core/Makefile b/core/Makefile
index 0b7aa88..7f4299e 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -118,6 +118,7 @@
 			PRODUCT_BRAND="$(PRODUCT_BRAND)" \
 			PRODUCT_DEFAULT_LANGUAGE="$(call default-locale-language,$(PRODUCT_LOCALES))" \
 			PRODUCT_DEFAULT_REGION="$(call default-locale-region,$(PRODUCT_LOCALES))" \
+			PRODUCT_DEFAULT_WIFI_CHANNELS="$(PRODUCT_DEFAULT_WIFI_CHANNELS)" \
 			PRODUCT_MODEL="$(PRODUCT_MODEL)" \
 			PRODUCT_MANUFACTURER="$(PRODUCT_MANUFACTURER)" \
 			PRIVATE_BUILD_DESC="$(PRIVATE_BUILD_DESC)" \
diff --git a/core/base_rules.mk b/core/base_rules.mk
index c182a77..1a55320 100644
--- a/core/base_rules.mk
+++ b/core/base_rules.mk
@@ -350,7 +350,6 @@
 $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_POST_PROCESS_COMMAND:= $(LOCAL_POST_PROCESS_COMMAND)
 $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_AAPT_FLAGS:= $(LOCAL_AAPT_FLAGS)
 $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_JAVA_LIBRARIES:= $(LOCAL_JAVA_LIBRARIES)
-#TODO: add this: $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ADDITIONAL_DEPENDENCIES:= $(LOCAL_ADDITIONAL_DEPENDENCIES)
 
 $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_ALL_JAVA_LIBRARIES:= $(full_java_libs)
 $(LOCAL_INTERMEDIATE_TARGETS) : PRIVATE_IS_HOST_MODULE := $(LOCAL_IS_HOST_MODULE)
diff --git a/core/binary.mk b/core/binary.mk
index ddcdc6f..4413d47 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -87,7 +87,7 @@
 ifneq ($(strip $(yacc_cpps)),)
 $(yacc_cpps): $(intermediates)/%$(LOCAL_CPP_EXTENSION): \
 		$(TOPDIR)$(LOCAL_PATH)/%.y \
-		$(lex_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+		$(lex_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(call transform-y-to-cpp,$(PRIVATE_CPP_EXTENSION))
 $(yacc_headers): $(intermediates)/%.h: $(intermediates)/%$(LOCAL_CPP_EXTENSION)
 
@@ -115,7 +115,7 @@
 $(lex_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
 $(lex_objects): $(intermediates)/%.o: \
 		$(intermediates)/%$(LOCAL_CPP_EXTENSION) \
-		$(PRIVATE_ADDITIONAL_DEPENDENCIES) \
+		$(LOCAL_ADDITIONAL_DEPENDENCIES) \
 		$(yacc_headers)
 	$(transform-$(PRIVATE_HOST)cpp-to-o)
 endif
@@ -142,7 +142,7 @@
 ifneq ($(strip $(cpp_objects)),)
 $(cpp_objects): $(intermediates)/%.o: \
 		$(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
-		$(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+		$(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)cpp-to-o)
 -include $(cpp_objects:%.o=%.P)
 endif
@@ -159,7 +159,7 @@
 # TODO: support compiling certain generated files as arm.
 $(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
 $(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
-$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)cpp-to-o)
 -include $(gen_cpp_objects:%.o=%.P)
 endif
@@ -172,7 +172,7 @@
 gen_S_objects := $(gen_S_sources:%.S=%.o)
 
 ifneq ($(strip $(gen_S_sources)),)
-$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_S_objects): $(intermediates)/%.o: $(intermediates)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)s-to-o)
 -include $(gen_S_objects:%.o=%.P)
 endif
@@ -181,7 +181,7 @@
 gen_s_objects := $(gen_s_sources:%.s=%.o)
 
 ifneq ($(strip $(gen_s_objects)),)
-$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(gen_s_objects): $(intermediates)/%.o: $(intermediates)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
 -include $(gen_s_objects:%.o=%.P)
 endif
@@ -206,12 +206,29 @@
 c_objects        := $(c_arm_objects) $(c_normal_objects)
 
 ifneq ($(strip $(c_objects)),)
-$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)c-to-o)
 -include $(c_objects:%.o=%.P)
 endif
 
 ###########################################################
+## C: Compile generated .c files to .o.
+###########################################################
+
+gen_c_sources := $(filter %.c,$(LOCAL_GENERATED_SOURCES))
+gen_c_objects := $(gen_c_sources:%.c=%.o)
+
+ifneq ($(strip $(gen_c_objects)),)
+# Compile all generated files as thumb.
+# TODO: support compiling certain generated files as arm.
+$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
+$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
+$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
+	$(transform-$(PRIVATE_HOST)c-to-o)
+-include $(gen_c_objects:%.o=%.P)
+endif
+
+###########################################################
 ## ObjC: Compile .m files to .o
 ###########################################################
 
@@ -232,7 +249,7 @@
 asm_objects_S := $(addprefix $(intermediates)/,$(asm_sources_S:.S=.o))
 
 ifneq ($(strip $(asm_objects_S)),)
-$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(asm_objects_S): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.S $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)s-to-o)
 -include $(asm_objects_S:%.o=%.P)
 endif
@@ -241,7 +258,7 @@
 asm_objects_s := $(addprefix $(intermediates)/,$(asm_sources_s:.s=.o))
 
 ifneq ($(strip $(asm_objects_s)),)
-$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(PRIVATE_ADDITIONAL_DEPENDENCIES)
+$(asm_objects_s): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.s $(LOCAL_ADDITIONAL_DEPENDENCIES)
 	$(transform-$(PRIVATE_HOST)s-to-o-no-deps)
 -include $(asm_objects_s:%.o=%.P)
 endif
@@ -261,6 +278,7 @@
 	$(gen_cpp_objects) \
 	$(gen_asm_objects) \
 	$(c_objects) \
+	$(gen_c_objects) \
 	$(yacc_objects) \
 	$(lex_objects) \
 	$(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
diff --git a/core/build-system.html b/core/build-system.html
new file mode 100644
index 0000000..43bae03
--- /dev/null
+++ b/core/build-system.html
@@ -0,0 +1,947 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<!--
+  A lot of people read this document template.  Please keep it clean:
+
+   - keep the document xhtml-compliant, as many people use validating editors
+   - check your edits for typos, spelling errors, and questionable grammar
+   - prefer css styles to formatting tags like <font>, <tt>, etc.
+   - keep it human-readable and human-editable in a plain text editor:
+     - strive to keep lines wrapped at 80 columns, unless a link prevents it
+     - use plenty of whitespace
+     - try to pretty-format (wrt nesting and indenting) any hairy html
+   - check your inline javascript for errors using the javascript console
+   
+  Your readers will be very appreciative.
+-->
+
+<head>
+  <title>Android Build System</title>
+
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+  <link href="../android.css" type="text/css" rel="stylesheet" />
+
+<!-- commenting out so the xhtml validator doesn't whine about < and &&;
+     the browser should still find the script tag. -->
+<script language="JavaScript1.2" type="text/javascript">
+<!--
+function highlight(name) {
+  if (document.getElementsByTagName) {
+    tags              = [ 'span', 'div', 'tr', 'td' ];
+    for (i in tags) {
+      elements        = document.getElementsByTagName(tags[i]);
+      if (elements) {
+        for (j = 0; j < elements.length; j++) {
+          elementName = elements[j].getAttribute("class");
+          if (elementName == name) {
+            elements[j].style.backgroundColor = "#C0F0C0";
+          } else if (elementName && elementName.indexOf("rev") == 0) {
+            elements[j].style.backgroundColor = "#FFFFFF";
+          }
+        }
+      }
+    }
+  }
+}
+//-->
+  </script>
+  <!-- this style sheet is for the style of the toc -->
+  <link href="toc.css" type="text/css" rel="stylesheet" />
+
+  <style type="text/css">
+    .warning {
+        border: 1px solid red;
+        padding: 8px;
+        color: red;
+    }
+    pre.prettyprint {
+        margin-top: 0;
+    }
+    li {
+        margin-top: 8px;
+    }
+  </style>
+</head>
+
+<body onload="prettyPrint()">
+
+<h1><a name="My_Project_" />Android Build System</h1>
+
+<!-- Status is one of: Draft, Current, Needs Update, Obsolete -->
+<p style="text-align:center">
+  <strong>Status:</strong> <em>Draft </em> &nbsp;
+  <small>(as of May 18, 2006)</small>
+</p>
+
+<p><b>Contents</b></p>
+<!-- this div expands out to a list of contents based on the H2 and H3 headings.
+Believe it! -->
+ <div id="nav"  class="nav-2-levels"></div>
+
+<h2>Objective</h2>
+<p>The primary goals of reworking the build system are (1) to make dependencies
+work more reliably, so that when files need to rebuilt, they are, and (2) to
+improve performance of the build system so that unnecessary modules are not
+rebuilt, and so doing a top-level build when little or nothing needs to be done
+for a build takes as little time as possible.</p>
+
+<h2>Principles and Use Cases and Policy</h2>
+<p>Given the above objective, these are the overall principles and use cases
+that we will support.  This is not an exhaustive list.</p>
+<h3>Multiple Targets</h3>
+<p>It needs to be possible to build the Android platform for multiple targets.
+This means:</p>
+<ul>
+    <li>The build system will support building tools for the host platform,
+    both ones that are used in the build process itself, and developer tools
+    like the simulator.</li>
+    <li>The build system will need to be able to build tools on Linux
+    (definitely Goobuntu and maybe Grhat), MacOS, and to some degree on
+    Windows.</li>
+    <li>The build system will need to be able to build the OS on Linux, and in
+    the short-term, MacOS.  Note that this is a conscious decision to stop
+    building the OS on Windows.  We are going to rely on the emulator there
+    and not attempt to use the simulator.  This is a requirement change now
+    that the emulator story is looking brighter.</li>
+</ul>
+<h3>Non-Recursive Make</h3>
+<p>To achieve the objectives, the build system will be rewritten to use make
+non-recursively.  For more background on this, read <a href="http://aegis.sourceforge.net/auug97.pdf">Recursive Make Considered Harmful</a>.  For those that don't
+want PDF, here is the
+<a href="http://72.14.203.104/search?q=cache:HwuX7YF2uBIJ:aegis.sourceforge.net/auug97.pdf&hl=en&gl=us&ct=clnk&cd=2&client=firefox">Google translated version</a>.
+<h3>Rapid Compile-Test Cycles</h3>
+<p>When developing a component, for example a C++ shared library, it must be
+possible to easily rebuild just that component, and not have to wait more than a
+couple seconds for dependency checks, and not have to wait for unneeded
+components to be built.</p>
+<h3>Both Environment and Config File Based Settings</h3>
+<p>To set the target, and other options, some people on the team like to have a
+configuration file in a directory so they do not have an environment setup
+script to run, and others want an environment setup script to run so they can
+run builds in different terminals on the same tree, or switch back and forth
+in one terminal.  We will support both.</p>
+<h3>Object File Directory / make clean</h3>
+<p>Object files and other intermediate files will be generated into a directory
+that is separate from the source tree.  The goal is to have make clean be
+"rm -rf <obj>" in the tree root directory.  The primary goals of
+this are to simplify searching the source tree, and to make "make clean" more
+reliable.</p>
+
+<h3>SDK</h3>
+<p>The SDK will be a tarball that will allow non-OS-developers to write apps.
+The apps will actually be built by first building the SDK, and then building
+the apps against that SDK.  This will hopefully (1) make writing apps easier
+for us, because we won't have to rebuild the OS as much, and we can use the
+standard java-app development tools, and (2) allow us to dog-food the SDK, to
+help ensure its quality.  Cedric has suggested (and I agree) that apps built
+from the SDK should be built with ant.  Stay tuned for more details as we
+figure out exactly how this will work.</p>
+
+<h3>Dependecies</h3>
+<p>Dependencies should all be automatic.  Unless there is a custom tool involved
+(e.g. the webkit has several), the dependencies for shared and static libraries,
+.c, .cpp, .h, .java, java libraries, etc., should all work without intervention
+in the Android.mk file.</p>
+
+<h3>Hiding command lines</h3>
+<p>The default of the build system will be to hide the command lines being
+executed for make steps.  It will be possible to override this by specifying
+the showcommands pseudo-target, and possibly by setting an environment
+variable.</p>
+
+<h3>Wildcard source files</h3>
+<p>Wildcarding source file will be discouraged.  It may be useful in some
+scenarios.  The default <code>$(wildcard *)</code> will not work due to the
+current directory being set to the root of the build tree.<p>
+
+<h3>Multiple targets in one directory</h3>
+<p>It will be possible to generate more than one target from a given
+subdirectory.  For example, libutils generates a shared library for the target
+and a static library for the host.</p>
+
+<h3>Makefile fragments for modules</h3>
+<p><b>Android.mk</b> is the standard name for the makefile fragments that
+control the building of a given module.  Only the top directory should
+have a file named "Makefile".</p>
+
+<h3>Use shared libraries</h3>
+<p>Currently, the simulator is not built to use shared libraries.  This should
+be fixed, and now is a good time to do it.  This implies getting shared
+libraries to work on Mac OS.</p>
+
+
+<h2>Nice to Have</h2>
+
+<p>These things would be nice to have, and this is a good place to record them,
+however these are not promises.</p>
+
+<h3>Simultaneous Builds</h3>
+<p>The hope is to be able to do two builds for different combos in the same
+tree at the same time, but this is a stretch goal, not a requirement.
+Doing two builds in the same tree, not at the same time must work.  (update:
+it's looking like we'll get the two builds at the same time working)</p>
+
+<h3>Deleting headers (or other dependecies)</h3>
+<p>Problems can arise if you delete a header file that is referenced in
+".d" files.  The easy way to deal with this is "make clean".  There
+should be a better way to handle it. (from fadden)</p>
+<p>One way of solving this is introducing a dependency on the directory.  The
+problem is that this can create extra dependecies and slow down the build.
+It's a tradeoff.</p>
+
+<h3>Multiple builds</h3>
+<p>General way to perform builds across the set of known platforms.  This
+would make it easy to perform multiple platform builds when testing a
+change, and allow a wide-scale "make clean".  Right now the buildspec.mk
+or environment variables need to be updated before each build. (from fadden)</p>
+
+<h3>Aftermarket Locales and Carrier</h3>
+<p>We will eventually need to add support for creating locales and carrier
+customizations to the SDK, but that will not be addressed right now.</p>
+
+
+<h2><a id="usage"/>Usage</h2>
+<p>You've read (or scrolled past) all of the motivations for this build system,
+and you want to know how to use it.  This is the place.</p>
+
+<h3>Your first build</h3>
+<p>The <a href="../building.html">Building</a> document describes how do do
+builds.</p>
+
+<h3>build/envsetup.sh functions</h3>
+If you source the file build/envsetup.sh into your bash environment,
+<code>. build/envsetup.sh</code>you'll get a few helpful shell functions:
+
+<ul>
+<li><b>printconfig</b> - Prints the current configuration as set by the
+lunch and choosecombo commands.</li>
+<li><b>m</b> - Runs <code>make</code> from the top of the tree.  This is
+useful because you can run make from within subdirectories.  If you have the
+<code>TOP</code> environment variable set, it uses that.  If you don't, it looks
+up the tree from the current directory, trying to find the top of the tree.</li>
+<li><b>croot</b> - <code>cd</code> to the top of the tree.</li>
+<li><b>sgrep</b> - grep for the regex you provide in all .c, .cpp, .h, .java,
+and .xml files below the current directory.</li>
+</ul>
+
+<h3>Build flavors/types</h3>
+<p>
+When building for a particular product, it's often useful to have minor
+variations on what is ultimately the final release build.  These are the
+currently-defined "flavors" or "types" (we need to settle on a real name
+for these).
+</p>
+
+<table border=1>
+<tr>
+    <td>
+        <code>eng<code>
+    </td>
+    <td>
+        This is the default flavor. A plain "<code>make</code>" is the
+        same as "<code>make eng</code>".  <code>droid</code> is an alias
+        for <code>eng</code>.
+        <ul>
+        <li>Installs modules tagged with: <code>eng</code>, <code>debug</code>,
+            <code>user</code>, and/or <code>development</code>.
+        <li>Installs non-APK modules that have no tags specified.
+        <li>Installs APKs according to the product definition files, in
+            addition to tagged APKs.
+        <li><code>ro.secure=0</code>
+        <li><code>ro.debuggable=1</code>
+        <li><code>ro.kernel.android.checkjni=1</code>
+        <li><code>adb</code> is enabled by default.
+    </td>
+</tr>
+<tr>
+    <td>
+        <code>user<code>
+    </td>
+    <td>
+        "<code>make user</code>"
+        <p>
+        This is the flavor intended to be the final release bits.
+        <ul>
+        <li>Installs modules tagged with <code>user</code>.
+        <li>Installs non-APK modules that have no tags specified.
+        <li>Installs APKs according to the product definition files; tags
+            are ignored for APK modules.
+        <li><code>ro.secure=1</code>
+        <li><code>ro.debuggable=0</code>
+        <li><code>adb</code> is disabled by default.
+    </td>
+</tr>
+<tr>
+    <td>
+        <code>userdebug<code>
+    </td>
+    <td>
+        "<code>make userdebug</code>"
+        <p>
+        The same as <code>user</code>, except:
+        <ul>
+        <li>Also installs modules tagged with <code>debug</code>.
+        <li><code>ro.debuggable=1</code>
+        <li><code>adb</code> is enabled by default.
+    </td>
+</tr>
+</table>
+
+<p>
+If you build one flavor and then want to build another, you should run
+"<code>make installclean</code>" between the two makes to guarantee that
+you don't pick up files installed by the previous flavor.  "<code>make
+clean</code>" will also suffice, but it takes a lot longer.
+</p>
+
+
+<h3>More pseudotargets</h3>
+<p>Sometimes you want to just build one thing.  The following pseudotargets are
+there for your convenience:</p>
+
+<ul>
+<li><b>droid</b> - <code>make droid</code> is the normal build.  This target
+is here because the default target has to have a name.</li>
+<li><b>all</b> - <code>make all</code> builds everything <code>make
+droid</code> does, plus everything whose <code>LOCAL_MODULE_TAGS</code> do not
+include the "droid" tag.  The build server runs this to make sure
+that everything that is in the tree and has an Android.mk builds.</li>
+<li><b>clean-$(LOCAL_MODULE)</b> and <b>clean-$(LOCAL_PACKAGE_NAME)</b> - 
+Let you selectively clean one target.  For example, you can type
+<code>make clean-libutils</code> and it will delete libutils.so and all of the
+intermediate files, or you can type <code>make clean-Home</code> and it will
+clean just the Home app.</li>
+<li><b>clean</b> - <code>make clean</code> deletes all of the output and
+intermediate files for this configuration.  This is the same as <code>rm -rf
+out/&lt;configuration&gt;/</code></li>
+<li><b>clobber</b> - <code>make clobber</code> deletes all of the output
+and intermediate files for all configurations.  This is the same as
+<code>rm -rf out/</code>.</li>
+<li><b>dataclean</b> - <code>make dataclean</code> deletes contents of the data 
+directory inside the current combo directory.  This is especially useful on the
+simulator and emulator, where the persistent data remains present between 
+builds.</li>
+<li><b>showcommands</b> - <code>showcommands</code> is a modifier target
+which causes the build system to show the actual command lines for the build
+steps, instead of the brief descriptions.  Most people don't like seeing the
+actual commands, because they're quite long and hard to read, but if you need
+to for debugging purposes, you can add <code>showcommands</code> to the list
+of targets you build.  For example <code>make showcommands</code> will build
+the default android configuration, and <code>make runtime showcommands</code>
+will build just the runtime, and targets that it depends on, while displaying
+the full command lines.  Please note that there are a couple places where the
+commands aren't shown here.  These are considered bugs, and should be fixed,
+but they're often hard to track down.  Please let
+<a href="mailto:android-build-team">android-build-team</a> know if you find
+any.</li>
+<li><b>LOCAL_MODULE</b> - Anything you specify as a <code>LOCAL_MODULE</code>
+in an Android.mk is made into a pseudotarget.  For example, <code>make
+runtime</code> might be shorthand for <code>make
+out/linux-x86-debug/system/bin/runtime</code> (which would work), and
+<code>make libkjs</code> might be shorthand for <code>make
+out/linux-x86-debug/system/lib/libkjs.so</code> (which would also work).</li>
+<li><b>targets</b> - <code>make targets</code> will print a list of all of
+the LOCAL_MODULE names you can make.</li>
+</ul>
+
+<h3><a name="templates"/>How to add another component to the build - Android.mk templates</h3>
+<p>You have a new library, a new app, or a new executable.  For each of the
+common types of modules, there is a corresponding file in the templates
+directory.  It will usually be enough to copy one of these, and fill in your
+own values.  Some of the more esoteric values are not included in the
+templates, but are instead just documented here, as is the documentation
+on using custom tools to generate files.</p>
+<p>Mostly, you can just look for the TODO comments in the templates and do
+what it says.  Please remember to delete the TODO comments when you're done
+to keep the files clean.  The templates have minimal documentation in them,
+because they're going to be copied, and when that gets stale, the copies just
+won't get updated.  So read on...</p>
+
+<h4>Apps</h4>
+<p>Use the <code>templates/apps</code> file.</p>
+<p>This template is pretty self-explanitory.  See the variables below for more
+details.</p>
+
+<h4>Java Libraries</h4>
+<p>Use the <code>templates/java_library</code> file.</p>
+<p>The interesting thing here is the value of LOCAL_MODULE, which becomes
+the name of the jar file.  (Actually right now, we're not making jar files yet,
+just directories of .class files,  but the directory is named according to
+what you put in LOCAL_MODULE).  This name will be what goes in the 
+LOCAL_JAVA_LIBRARIES variable in modules that depend on your java library.</p>
+
+<h4>C/C++ Executables</h4>
+<p>Use the <code>templates/executable</code> file, or the
+<code>templates/executable_host</code> file.</p>
+<p>This template has a couple extra options that you usually don't need.
+Please delete the ones you don't need, and remove the TODO comments.  It makes
+the rest of them easier to read, and you can always refer back to the templates
+if you need them again later.</p>
+<p>By default, on the target these are built into /system/bin, and on the
+host, they're built into <combo>/host/bin.  These can be overridden by setting
+<code>LOCAL_MODULE_PATH</code>.  See
+<a href="#moving-targets">Putting targets elsewhere</a>
+for more.</p>
+
+<h4>Shared Libraries</h4>
+<p>Use the <code>templates/shared_library</code> file, or the
+<code>templates/shared_library_host</code> file.</p>
+<p>Remember that on the target, we use shared libraries, and on the host,
+we use static libraries, since executable size isn't as big an issue, and it
+simplifies distribution in the SDK.</p>
+
+<h4>Static Libraries</h4>
+<p>Use the <code>templates/static_library</code> file, or the
+<code>templates/static_library_host</code> file.</p>
+<p>Remember that on the target, we use shared libraries, and on the host,
+we use static libraries, since executable size isn't as big an issue, and it
+simplifies distribution in the SDK.</p>
+
+<h4><a name="custom-tools"/>Using Custom Tools</h4>
+<p>If you have a tool that generates source files for you, it's possible
+to have the build system get the dependencies correct for it.  Here are
+a couple of examples.  <code>$@</code> is the make built-in variable for
+"the current target." The <font color=red>red</font> parts are the parts you'll
+need to change.</p>
+
+<p>You need to put this after you have declared <code>LOCAL_PATH</code> and
+<code>LOCAL_MODULE</code>, because the <code>$(local-intermediates-dir)</code>
+and <code>$(local-host-intermediates-dir)</code> macros use these variables
+to determine where to put the files.
+
+<h5>Example 1</h5>
+<p>Here, there is one generated file, called
+chartables.c, which doesn't depend on anything.  And is built by the tool
+built to $(HOST_OUT_EXECUTABLES)/dftables.  Note on the second to last line
+that a dependency is created on the tool.</p>
+<pre>
+intermediates:= $(local-intermediates-dir)
+GEN := $(intermediates)/<font color=red>chartables.c</font>
+$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>$(HOST_OUT_EXECUTABLES)/dftables $@</font>
+$(GEN): <font color=red>$(HOST_OUT_EXECUTABLES)/dftables</font>
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+</pre>
+
+<h5>Example 2</h5>
+<p>Here as a hypothetical example, we use use cat as if it were to transform
+a file.  Pretend that it does something useful.  Note how we use a
+target-specific variable called PRIVATE_INPUT_FILE to store the name of the
+input file.</p>
+<pre>
+intermediates:= $(local-intermediates-dir)
+GEN := $(intermediates)/<font color=red>file.c</font>
+$(GEN): PRIVATE_INPUT_FILE := $(LOCAL_PATH)/<font color=red>input.file</font>
+$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>cat $(PRIVATE_INPUT_FILE) &gt; $@</font>
+$(GEN): <font color=red>$(LOCAL_PATH)/file.c</font>
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+</pre>
+
+<h5>Example 3</h5>
+<p>If you have several files that are all similar in
+name, and use the same tool, you can combine them.  (here the *.lut.h files are
+the generated ones, and the *.cpp files are the input files)</p>
+<pre>
+intermediates:= $(local-intermediates-dir)
+GEN := $(addprefix $(intermediates)<font color=red>/kjs/, \
+            array_object.lut.h \
+            bool_object.lut.h \</font>
+        )
+$(GEN): PRIVATE_CUSTOM_TOOL = <font color=red>perl libs/WebKitLib/WebKit/JavaScriptCore/kjs/create_hash_table $< -i > $@</font>
+$(GEN): $(intermediates)/<font color=red>%.lut.h</font> : $(LOCAL_PATH)/<font color=red>%.cpp</font>
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+</pre>
+
+<h3><a name="platform-specific"/>Platform specific conditionals</h3>
+<p>Sometimes you need to set flags specifically for different platforms.  Here
+is a list of which values the different build-system defined variables will be
+set to and some examples.</p>
+<p>For a device build, <code>TARGET_OS</code> is <code>linux</code> (we're using
+linux!), and <code>TARGET_ARCH</code> is <code>arm</code>.</p>
+<p>For a simulator build, <code>TARGET_OS</code> and <code>TARGET_ARCH</code>
+are set to the same as <code>HOST_OS</code> and <code>HOST_ARCH</code> are
+on your platform.  <code>TARGET_PRODUCT</code> is the name of the target
+hardware/product you are building for.  The value <code>sim</code> is used
+for the simulator.  We haven't thought through the full extent of customization
+that will happen here, but likely there will be additional UI configurations
+specified here as well.</p>
+<table cellspacing=25>
+<tr>
+    <td valign=top align=center>
+        <b>HOST_OS</b><br/>
+        linux<br/>
+        darwin<br/>
+        (cygwin)
+    </td>
+    <td valign=top align=center>
+        <b>HOST_ARCH</b><br/>
+        x86
+    </td>
+    <td valign=top align=center>
+        <b>HOST_BUILD_TYPE</b><br/>
+        release<br/>
+        debug
+    </td>
+</tr>
+<tr>
+    <td valign=top align=center>
+        <b>TARGET_OS</b><br/>
+        linux<br/>
+        darwin<br/>
+        (cygwin)
+    </td>
+    <td valign=top align=center>
+        <b>TARGET_ARCH</b><br/>
+        arm<br/>
+        x86
+    </td>
+    <td valign=top align=center>
+        <b>TARGET_BUILD_TYPE</b><br/>
+        release<br/>
+        debug
+    </td>
+    <td valign=top align=center>
+        <b>TARGET_PRODUCT</b><br/>
+        sim<br/>
+        dream<br/>
+        sooner
+    </td>
+</tr>
+</table>
+
+<h4>TARGET_SIMULATOR</h4>
+<p>If we're building the simulator, as opposed to the arm or emulator builds,
+<code>TARGET_SIMULATOR</code> will be set to <code>true</code>.
+
+<h4>Some Examples</h4>
+<pre>ifeq ($(TARGET_SIMULATOR),true)
+LOCAL_CFLAGS += -DSIMULATOR
+endif
+
+ifeq ($(TARGET_BUILD_TYPE),release)
+LOCAL_CFLAGS += -DNDEBUG=1
+endif
+
+# from libutils
+ifeq ($(TARGET_OS),linux)
+# Use the futex based mutex and condition variable
+# implementation from android-arm because it's shared mem safe
+LOCAL_SRC_FILES += futex_synchro.c
+LOCAL_LDLIBS += -lrt -ldl
+endif
+
+</pre>
+
+
+<h3><a name="moving-modules"/>Putting modules elsewhere</h3>
+<p>If you have modules that normally go somewhere, and you need to have them
+build somewhere else, read this.  One use of this is putting files on
+the root filesystem instead of where they normally go in /system. Add these
+lines to your Android.mk:</p>
+<pre>
+LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT_SBIN)
+LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_SBIN_UNSTRIPPED)
+</pre>
+<p>For executables and libraries, you need to also specify a
+<code>LOCAL_UNSTRIPPED_PATH</code> location, because on target builds, we keep
+the unstripped executables so GDB can find the symbols.</code>
+<p>Look in <code>config/envsetup.make</code> for all of the variables defining
+places to build things.</p>
+<p>FYI: If you're installing an executable to /sbin, you probably also want to
+set <code>LOCAL_FORCE_STATIC_EXCUTABLE := true</code> in your Android.mk, which
+will force the linker to only accept static libraries.</p>
+
+
+<h3>Android.mk variables</h3>
+<p>These are the variables that you'll commonly see in Android.mk files, listed
+alphabetically.</p>
+<p>But first, a note on variable naming:
+<ul>
+    <li><b>LOCAL_</b> - These variables are set per-module.  They are cleared
+    by the <code>include $(CLEAR_VARS)</code> line, so you can rely on them
+    being empty after including that file.  Most of the variables you'll use
+    in most modules are LOCAL_ variables.</li>
+    <li><b>PRIVATE_</b> - These variables are make-target-specific variables.  That
+    means they're only usable within the commands for that module.  It also
+    means that they're unlikely to change behind your back from modules that
+    are included after yours.  This 
+    <a href="http://www.gnu.org/software/make/manual/make.html#Target_002dspecific">link to the make documentation</a>
+    describes more about target-specific variables.  Please note that there
+    are a couple of these laying around the tree that aren't prefixed with
+    PRIVATE_.  It is safe, and they will be fixed as they are discovered.
+    Sorry for the confusion.</li>
+    <li><b>INTERNAL_</b> - These variables are critical to functioning of
+    the build system, so you shouldn't create variables named like this, and
+    you probably shouldn't be messing with these variables in your makefiles.
+    </li>
+    <li><b>HOST_</b> and <b>TARGET_</b> - These contain the directories
+    and definitions that are specific to either the host or the target builds.
+    Do not set variables that start with HOST_ or TARGET_ in your makefiles.
+    </li>
+    <li><b>BUILD_</b> and <b>CLEAR_VARS</b> - These contain the names of
+    well-defined template makefiles to include.  Some examples are CLEAR_VARS
+    and BUILD_HOST_PACKAGE.</li>
+    <li>Any other name is fair-game for you to use in your Android.mk.  However,
+    remember that this is a non-recursive build system, so it is possible that
+    your variable will be changed by another Android.mk included later, and be
+    different when the commands for your rule / module are executed.</li>
+</ul>
+</p>
+
+<h4>LOCAL_ASSET_FILES</h4>
+<p>In Android.mk files that <code>include $(BUILD_PACKAGE)</code> set this
+to the set of files you want built into your app.  Usually:</p>
+<p><code>LOCAL_ASSET_FILES += $(call find-subdir-assets)</code></p>
+<p>This will probably change when we switch to ant for the apps' build
+system.</p>
+
+<h4>LOCAL_CC</h4>
+<p>If you want to use a different C compiler for this module, set LOCAL_CC
+to the path to the compiler.  If LOCAL_CC is blank, the appropriate default
+compiler is used.</p>
+
+<h4>LOCAL_CXX</h4>
+<p>If you want to use a different C++ compiler for this module, set LOCAL_CXX
+to the path to the compiler.  If LOCAL_CXX is blank, the appropriate default
+compiler is used.</p>
+
+<h4>LOCAL_CFLAGS</h4>
+<p>If you have additional flags to pass into the C or C++ compiler, add
+them here.  For example:</p>
+<p><code>LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1</code></p>
+
+<h4>LOCAL_CPPFLAGS</h4>
+<p>If you have additional flags to pass into <i>only</i> the C++ compiler, add
+them here.  For example:</p>
+<p><code>LOCAL_CPPFLAGS += -ffriend-injection</code></p>
+<code>LOCAL_CPPFLAGS</code> is guaranteed to be after <code>LOCAL_CFLAGS</code>
+on the compile line, so you can use it to override flags listed in
+<code>LOCAL_CFLAGS</code>.
+
+<h4>LOCAL_CPP_EXTENSION</h4>
+<p>If your C++ files end in something other than "<code>.cpp</code>",
+you can specify the custom extension here.  For example:</p>
+<p><code>LOCAL_CPP_EXTENSION := .cc</code></p>
+Note that all C++ files for a given module must have the same
+extension; it is not currently possible to mix different extensions.
+
+<h4>LOCAL_NO_DEFAULT_COMPILER_FLAGS</h4>
+<p>Normally, the compile line for C and C++ files includes global include
+paths and global cflags.  If <code>LOCAL_NO_DEFAULT_COMPILER_FLAGS</code>
+is non-empty, none of the default includes or flags will be used when compiling
+C and C++ files in this module.
+<code>LOCAL_C_INCLUDES</code>, <code>LOCAL_CFLAGS</code>, and
+<code>LOCAL_CPPFLAGS</code> will still be used in this case, as will
+any <code>DEBUG_CFLAGS</code> that are defined for the module.
+
+<h4>LOCAL_COPY_HEADERS</h4>
+<p class=warning>This will be going away.</p>
+<p>The set of files to copy to the install include tree.  You must also
+supply <code>LOCAL_COPY_HEADERS_TO</code>.</p>
+<p>This is going away because copying headers messes up the error messages, and
+may lead to people editing those headers instead of the correct ones.  It also
+makes it easier to do bad layering in the system, which we want to avoid.  We
+also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any
+headers.</p>
+
+<h4>LOCAL_COPY_HEADERS_TO</h4>
+<p class=warning>This will be going away.</p>
+<p>The directory within "include" to copy the headers listed in
+<code>LOCAL_COPY_HEADERS</code> to.</p>
+<p>This is going away because copying headers messes up the error messages, and
+may lead to people editing those headers instead of the correct ones.  It also
+makes it easier to do bad layering in the system, which we want to avoid.  We
+also aren't doing a C/C++ SDK, so there is no ultimate requirement to copy any
+headers.</p>
+
+<h4>LOCAL_C_INCLUDES</h4>
+<p>Additional directories to instruct the C/C++ compilers to look for header
+files in.  These paths are rooted at the top of the tree.  Use
+<code>LOCAL_PATH</code> if you have subdirectories of your own that you
+want in the include paths.  For example:</p>
+<p><code>
+LOCAL_C_INCLUDES += extlibs/zlib-1.2.3<br/>
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
+</code></p>
+<p>You should not add subdirectories of include to
+<code>LOCAL_C_INCLUDES</code>, instead you should reference those files
+in the <code>#include</code> statement with their subdirectories.  For
+example:</p>
+<p><code>#include &lt;utils/KeyedVector.h&gt;</code><br/>
+not <code><s>#include &lt;KeyedVector.h&gt;</s></code></p>
+<p>There are some components that are doing this wrong, and should be cleaned
+up.</p>
+
+<h4>LOCAL_MODULE_TAGS</h4>
+<p>Set <code>LOCAL_MODULE_TAGS</code> to any number of whitespace-separated
+tags.  If the tag list is empty or contains <code>droid</code>, the module
+will get installed as part of a <code>make droid</code>.  Otherwise, it will
+only get installed by running <code>make &lt;your-module&gt;</code>
+or with the <code>make all</code> pseudotarget.</p>
+
+<h4>LOCAL_REQUIRED_MODULES</h4>
+<p>Set <code>LOCAL_REQUIRED_MODULES</code> to any number of whitespace-separated
+module names, like "libblah" or "Email".  If this module is installed, all
+of the modules that it requires will be installed as well.  This can be
+used to, e.g., ensure that necessary shared libraries or providers are
+installed when a given app is installed.
+
+<h4>LOCAL_FORCE_STATIC_EXECUTABLE</h4>
+<p>If your executable should be linked statically, set 
+<code>LOCAL_FORCE_STATIC_EXECUTABLE:=true</code>.  There is a very short
+list of libraries that we have in static form (currently only libc).  This is
+really only used for executables in /sbin on the root filesystem.</p>
+
+<h4>LOCAL_GENERATED_SOURCES</h4>
+<p>Files that you add to <code>LOCAL_GENERATED_SOURCES</code> will be
+automatically generated and then linked in when your module is built.
+See the <a href="#custom-tools">Custom Tools</a> template makefile for an
+example.</p>
+
+<h4>LOCAL_JAVA_LIBRARIES</h4>
+<p>When linking Java apps and libraries, <code>LOCAL_JAVA_LIBRARIES</code>
+specifies which sets of java classes to include.  Currently there are
+two of these: <code>core</code> and <code>framework</code>.
+In most cases, it will look like this:</p>
+<p><code>LOCAL_JAVA_LIBRARIES := core framework</code></p>
+<p>Note that setting <code>LOCAL_JAVA_LIBRARIES</code> is not necessary
+(and is not allowed) when building an APK with
+"<code>include $(BUILD_PACKAGE)</code>".  The appropriate libraries
+will be included automatically.</p>
+
+<h4>LOCAL_LDFLAGS</h4>
+<p>You can pass additional flags to the linker by setting
+<code>LOCAL_LDFLAGS</code>.  Keep in mind that the order of parameters is
+very important to ld, so test whatever you do on all platforms.</p>
+
+<h4>LOCAL_LDLIBS</h4>
+<p><code>LOCAL_LDLIBS</code> allows you to specify additional libraries
+that are not part of the build for your executable or library.  Specify
+the libraries you want in -lxxx format; they're passed directly to the 
+link line.  However, keep in mind that there will be no dependency generated
+for these libraries.  It's most useful in simulator builds where you want
+to use a library preinstalled on the host.  The linker (ld) is a particularly
+fussy beast, so it's sometimes necessary to pass other flags here if you're
+doing something sneaky. Some examples:</p>
+<p><code>LOCAL_LDLIBS += -lcurses -lpthread<br/>
+LOCAL_LDLIBS += -Wl,-z,origin
+</code></p>
+
+<h4>LOCAL_NO_MANIFEST</h4>
+<p>If your package doesn't have a manifest (AndroidManifest.xml), then
+set <code>LOCAL_NO_MANIFEST:=true</code>.  The common resources package
+does this.</p>
+
+<h4>LOCAL_PACKAGE_NAME</h4>
+<p><code>LOCAL_PACKAGE_NAME</code> is the name of an app.  For example,
+Dialer, Contacts, etc.  This will probably change or go away when we switch
+to an ant-based build system for the apps.</p>
+
+<h4>LOCAL_PATH</h4>
+<p>The directory your Android.mk file is in. You can set it by putting the
+following as the first line in your Android.mk:</p>
+<p><code>LOCAL_PATH := $(my-dir)</code></p>
+<p>The <code>my-dir</code> macro uses the 
+<code><a href="http://www.gnu.org/software/make/manual/make.html#MAKEFILE_005fLIST-Variable">MAKEFILE_LIST</a></code>
+variable, so you must call it before you include any other makefiles.  Also,
+consider that any subdirectories you inlcude might reset LOCAL_PATH, so do your
+own stuff before you include them.  This also means that if you try to write
+several <code>include</code> lines that reference <code>LOCAL_PATH</code>,
+it won't work, because those included makefiles might reset LOCAL_PATH.
+
+<h4>LOCAL_POST_PROCESS_COMMAND</h4>
+<p>For host executables, you can specify a command to run on the module
+after it's been linked.  You might have to go through some contortions
+to get variables right because of early or late variable evaluation:</p>
+<p><code>module := $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)<br/>
+LOCAL_POST_PROCESS_COMMAND := /Developer/Tools/Rez -d __DARWIN__ -t APPL\<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-d __WXMAC__ -o $(module) Carbon.r
+</code></p>
+
+<h4>LOCAL_PREBUILT_EXECUTABLES</h4>
+<p>When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to
+executables that you want copied.  They're located automatically into the
+right bin directory.</p>
+
+<h4>LOCAL_PREBUILT_LIBS</h4>
+<p>When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these to
+libraries that you want copied.  They're located automatically into the
+right lib directory.</p>
+
+<h4>LOCAL_SHARED_LIBRARIES</h4>
+<p>These are the libraries you directly link against.  You don't need to
+pass transitively included libraries.  Specify the name without the suffix:</p>
+<p><code>LOCAL_SHARED_LIBRARIES := \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libutils \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libui \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libaudio \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libexpat \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libsgl
+</code></p>
+
+<h4>LOCAL_SRC_FILES</h4>
+<p>The build system looks at <code>LOCAL_SRC_FILES</code> to know what source
+files to compile -- .cpp .c .y .l .java.  For lex and yacc files, it knows
+how to correctly do the intermediate .h and .c/.cpp files automatically.  If
+the files are in a subdirectory of the one containing the Android.mk, prefix
+them with the directory name:</p>
+<p><code>LOCAL_SRC_FILES := \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;file1.cpp \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;dir/file2.cpp
+</code></p>
+
+<h4>LOCAL_STATIC_LIBRARIES</h4>
+<p>These are the static libraries that you want to include in your module.
+Mostly, we use shared libraries, but there are a couple of places, like
+executables in sbin and host executables where we use static libraries instead.
+<p><code>LOCAL_STATIC_LIBRARIES := \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libutils \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libtinyxml
+</code></p>
+
+<h4>LOCAL_MODULE</h4>
+<p><code>LOCAL_MODULE</code> is the name of what's supposed to be generated
+from your Android.mk.  For exmample, for libkjs, the <code>LOCAL_MODULE</code>
+is "libkjs" (the build system adds the appropriate suffix -- .so .dylib .dll).
+For app modules, use <code>LOCAL_PACKAGE_NAME</code> instead of 
+<code>LOCAL_MODULE</code>.  We're planning on switching to ant for the apps,
+so this might become moot.</p>
+
+<h4>LOCAL_MODULE_PATH</h4>
+<p>Instructs the build system to put the module somewhere other than what's
+normal for its type.  If you override this, make sure you also set
+<code>LOCAL_UNSTRIPPED_PATH</code> if it's an executable or a shared library
+so the unstripped binary has somewhere to go.  An error will occur if you forget
+to.</p>
+<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p>
+
+<h4>LOCAL_UNSTRIPPED_PATH</h4>
+<p>Instructs the build system to put the unstripped version of the module
+somewhere other than what's normal for its type.  Usually, you override this
+because you overrode <code>LOCAL_MODULE_PATH</code> for an executable or a
+shared library.  If you overrode <code>LOCAL_MODULE_PATH</code>, but not 
+<code>LOCAL_UNSTRIPPED_PATH</code>, an error will occur.</p>
+<p>See <a href="#moving-modules">Putting modules elsewhere</a> for more.</p>
+
+<h4>LOCAL_WHOLE_STATIC_LIBRARIES</h4>
+<p>These are the static libraries that you want to include in your module without allowing
+the linker to remove dead code from them. This is mostly useful if you want to add a static library
+to a shared library and have the static library's content exposed from the shared library.
+<p><code>LOCAL_WHOLE_STATIC_LIBRARIES := \<br/>
+	&nbsp;&nbsp;&nbsp;&nbsp;libsqlite3_android<br/>
+</code></p>
+
+<h4>LOCAL_YACCFLAGS</h4>
+<p>Any flags to pass to invocations of yacc for your module.  A known limitation
+here is that the flags will be the same for all invocations of YACC for your
+module.  This can be fixed.  If you ever need it to be, just ask.</p>
+<p><code>LOCAL_YACCFLAGS := -p kjsyy</code></p>
+
+
+
+<h2>Implementation Details</h2>
+
+<p>You should never have to touch anything in the config directory unless
+you're adding a new platform, new tools, or adding new features to the
+build system.  In general, please consult with the build system owner(s)
+(<a href="mailto:android-build-team">android-build-team</a>) before you go
+mucking around in here.  That said, here are some notes on what's going on
+under the hood.</p>
+
+<h3>Environment Setup / buildspec.mk Versioning</h3>
+<p>In order to make easier for people when the build system changes, when
+it is necessary to make changes to buildspec.mk or to rerun the environment
+setup scripts, they contain a version number in the variable
+BUILD_ENV_SEQUENCE_NUMBER.  If this variable does not match what the build
+system expects, it fails printing an error message explaining what happened.
+If you make a change that requires an update, you need to update two places
+so this message will be printed.
+<ul>
+    <li>In config/envsetup.make, increment the
+        CORRECT_BUILD_ENV_SEQUENCE_NUMBER definition.</li>
+    <li>In buildspec.mk.default, update the BUILD_ENV_SEQUENCE_DUMBER
+        definition to match the one in config/envsetup.make</li>
+</ul>
+The scripts automatically get the value from the build system, so they will
+trigger the warning as well.
+</p>
+
+<h3>Additional makefile variables</h3>
+<p>You probably shouldn't use these variables.  Please consult
+<a href="mailto:android-build-team">android-build-team</a> before using them.
+These are mostly there for workarounds for other issues, or things that aren't
+completely done right.</p>
+
+<h4>LOCAL_ADDITIONAL_DEPENDENCIES</h4>
+<p>If your module needs to depend on anything else that
+isn't actually built in to it, you can add those make targets to 
+<code>LOCAL_ADDITIONAL_DEPENDENCIES</code>.  Usually this is a workaround
+for some other dependency that isn't created automatically.</p>
+
+<h4>LOCAL_BUILT_MODULE</h4>
+<p>When a module is built, the module is created in an intermediate
+directory then copied to its final location.  LOCAL_BUILT_MODULE is
+the full path to the intermediate file.  See LOCAL_INSTALLED_MODULE
+for the path to the final installed location of the module.</p>
+
+<h4>LOCAL_HOST</h4>
+<p>Set by the host_xxx.make includes to tell base_rules.make and the other
+includes that we're building for the host.  Kenneth did this as part of
+openbinder, and I would like to clean it up so the rules, includes and
+definitions aren't duplicated for host and target.</p>
+
+<h4>LOCAL_INSTALLED_MODULE</h4>
+<p>The fully qualified path name of the final location of the module.
+See LOCAL_BUILT_MODULE for the location of the intermediate file that
+the make rules should actually be constructing.</p>
+
+<h4>LOCAL_REPLACE_VARS</h4>
+<p>Used in some stuff remaining from the openbinder for building scripts
+with particular values set,</p>
+
+<h4>LOCAL_SCRIPTS</h4>
+<p>Used in some stuff remaining from the openbinder build system that we
+might find handy some day.</p>
+
+<h4>LOCAL_MODULE_CLASS</h4>
+<p>Which kind of module this is.  This variable is used to construct other
+variable names used to locate the modules.  See base_rules.make and
+envsetup.make.</p>
+
+<h4>LOCAL_MODULE_NAME</h4>
+<p>Set to the leaf name of the LOCAL_BUILT_MODULE.  I'm not sure,
+but it looks like it's just used in the WHO_AM_I variable to identify
+in the pretty printing what's being built.</p>
+
+<h4>LOCAL_MODULE_SUFFIX</h4>
+<p>The suffix that will be appended to <code>LOCAL_MODULE</code> to form
+<code>LOCAL_MODULE_NAME</code>.  For example, .so, .a, .dylib.</p>
+
+<h4>LOCAL_STRIP_MODULE</h4>
+<p>Calculated in base_rules.make to determine if this module should actually
+be stripped or not, based on whether <code>LOCAL_STRIPPABLE_MODULE</code>
+is set, and whether the combo is configured to ever strip modules.  With
+Iliyan's stripping tool, this might change.</p>
+
+<h4>LOCAL_STRIPPABLE_MODULE</h4>
+<p>Set by the include makefiles if that type of module is strippable. 
+Executables and shared libraries are.</p>
+
+<h4>LOCAL_SYSTEM_SHARED_LIBRARIES</h4>
+<p>Used while building the base libraries: libc, libm, libdl.  Usually
+it should be set to "none," as it is in $(CLEAR_VARS).  When building
+these libraries, it's set to the ones they link against.  For example,
+libc, libstdc++ and libdl don't link against anything, and libm links against
+libc.  Normally, when the value is none, these libraries are automatically
+linked in to executables and libraries, so you don't need to specify them
+manually.</p>
+
+
+</body>
+</html>
diff --git a/core/build_id.mk b/core/build_id.mk
index 9163cdf..40bb35d 100644
--- a/core/build_id.mk
+++ b/core/build_id.mk
@@ -23,7 +23,7 @@
 # (like "TC1-RC5").  It must be a single word, and is
 # capitalized by convention.
 #
-BUILD_ID := DONUT-BURGER
+BUILD_ID := MASTER
 
 # DISPLAY_BUILD_NUMBER should only be set for development branches,
 # If set, the BUILD_NUMBER (cl) is appended to the BUILD_ID for
diff --git a/core/combo/arch/arm/armv4t.mk b/core/combo/arch/arm/armv4t.mk
new file mode 100644
index 0000000..abc8fa2
--- /dev/null
+++ b/core/combo/arch/arm/armv4t.mk
@@ -0,0 +1,23 @@
+# Configuration for Linux on ARM.
+# Generating binaries for the ARMv4T architecture and higher
+#
+# Supporting armv4 (without thumb) does not make much sense since
+# it's mostly an obsoleted instruction set architecture (only available
+# in StrongArm and arm8). Supporting armv4 will require a lot of conditional
+# code in assembler source since the bx (branch and exchange) instruction is
+# not supported.
+#
+$(warning ARMv4t support is currently a work in progress. It does not work right now!)
+ARCH_ARM_HAVE_THUMB_SUPPORT := false
+ARCH_ARM_HAVE_THUMB_INTERWORKING := false
+ARCH_ARM_HAVE_64BIT_DATA := false
+ARCH_ARM_HAVE_HALFWORD_MULTIPLY := false
+ARCH_ARM_HAVE_CLZ := false
+ARCH_ARM_HAVE_FFS := false
+
+DEFAULT_TARGET_CPU := arm920t
+
+# Note: Hard coding the 'tune' value here is probably not ideal,
+# and a better solution should be found in the future.
+#
+arch_variant_cflags := -march=armv4t -mtune=arm920t -D__ARM_ARCH_4T__
diff --git a/core/combo/arch/arm/armv5te-vfp.mk b/core/combo/arch/arm/armv5te-vfp.mk
new file mode 100644
index 0000000..75299ac
--- /dev/null
+++ b/core/combo/arch/arm/armv5te-vfp.mk
@@ -0,0 +1,7 @@
+# At the moment, use the same settings than the one
+# for armv5te, since TARGET_ARCH_VARIANT := armv5te-vfp
+# will only be used to select an optimized VFP-capable assembly
+# interpreter loop for Dalvik.
+#
+include $(BUILD_COMBOS)/arch/arm/armv5te.mk
+
diff --git a/core/combo/arch/arm/armv5te.mk b/core/combo/arch/arm/armv5te.mk
new file mode 100644
index 0000000..29aada6
--- /dev/null
+++ b/core/combo/arch/arm/armv5te.mk
@@ -0,0 +1,21 @@
+# Configuration for Linux on ARM.
+# Generating binaries for the ARMv5TE architecture and higher
+#
+ARCH_ARM_HAVE_THUMB_SUPPORT     := true
+ARCH_ARM_HAVE_FAST_INTERWORKING := true
+ARCH_ARM_HAVE_64BIT_DATA        := true
+ARCH_ARM_HAVE_HALFWORD_MULTIPLY := true
+ARCH_ARM_HAVE_CLZ               := true
+ARCH_ARM_HAVE_FFS               := true
+
+# Note: Hard coding the 'tune' value here is probably not ideal,
+# and a better solution should be found in the future.
+#
+arch_variant_cflags := \
+    -march=armv5te \
+    -mtune=xscale  \
+    -D__ARM_ARCH_5__ \
+    -D__ARM_ARCH_5T__ \
+    -D__ARM_ARCH_5E__ \
+    -D__ARM_ARCH_5TE__
+
diff --git a/core/combo/linux-arm.mk b/core/combo/linux-arm.mk
index edd2df4..670c4b4 100644
--- a/core/combo/linux-arm.mk
+++ b/core/combo/linux-arm.mk
@@ -1,6 +1,40 @@
 # Configuration for Linux on ARM.
 # Included by combo/select.make
 
+# You can set TARGET_ARCH_VARIANT to use an arch version other
+# than ARMv5TE. Each value should correspond to a file named
+# $(BUILD_COMBOS)/arch/<name>.mk which must contain
+# makefile variable definitions similar to the preprocessor
+# defines in system/core/include/arch/<combo>/AndroidConfig.h. Their
+# purpose is to allow module Android.mk files to selectively compile
+# different versions of code based upon the funtionality and
+# instructions available in a given architecture version.
+#
+# The blocks also define specific arch_variant_cflags, which
+# include defines, and compiler settings for the given architecture
+# version.
+#
+ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
+TARGET_ARCH_VARIANT := armv5te
+endif
+
+# TARGET_ARCH_VARIANT used to be called TARGET_ARCH_VERSION
+# to avoid any weirdness, issue an error message if the latter
+# is defined.
+#
+ifneq ($(strip $(TARGET_ARCH_VERSION)),)
+$(info Definition for TARGET_ARCH_VERSION encountered !)
+$(info This variable has been renamed TARGET_ARCH_VARIANT, please update your build files !!)
+$(error Aborting the build.)
+endif
+
+TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
+ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
+$(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
+endif
+
+include $(TARGET_ARCH_SPECIFIC_MAKEFILE)
+
 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 ifeq ($(strip $($(combo_target)TOOLS_PREFIX)),)
 $(combo_target)TOOLS_PREFIX := \
@@ -21,11 +55,19 @@
                         -funswitch-loops     \
                         -finline-limit=300
 
+# Modules can choose to compile some source as thumb. As
+# non-thumb enabled targets are supported, this is treated
+# as a 'hint'. If thumb is not enabled, these files are just
+# compiled as ARM.
+ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
 TARGET_thumb_CFLAGS :=  -mthumb \
                         -Os \
                         -fomit-frame-pointer \
                         -fno-strict-aliasing \
                         -finline-limit=64
+else
+TARGET_thumb_CFLAGS := $(TARGET_arm_CFLAGS)
+endif
 
 # Set FORCE_ARM_DEBUGGING to "true" in your buildspec.mk
 # or in your environment to force a full arm build, even for
@@ -37,26 +79,32 @@
 # with -mlong-calls.  When built at -O0, those libraries are
 # too big for a thumb "BL <label>" to go from one end to the other.
 ifeq ($(FORCE_ARM_DEBUGGING),true)
-  TARGET_arm_CFLAGS += -fno-omit-frame-pointer
+  TARGET_arm_CFLAGS += -fno-omit-frame-pointer -fno-strict-aliasing
   TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
 endif
 
-## on some hosts, the target cross-compiler is not available so do not run this command
-ifneq ($(wildcard $($(combo_target)CC)),)
-$(combo_target)LIBGCC := $(shell $($(combo_target)CC) -mthumb-interwork -print-libgcc-file-name)
-endif
+android_config_h := $(call select-android-config-h,linux-arm)
+arch_include_dir := $(dir $(android_config_h))
 
 $(combo_target)GLOBAL_CFLAGS += \
-			-march=armv5te -mtune=xscale \
 			-msoft-float -fpic \
-			-mthumb-interwork \
 			-ffunction-sections \
 			-funwind-tables \
 			-fstack-protector \
 			-fno-short-enums \
-			-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ \
-			-D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ \
-			-include $(call select-android-config-h,linux-arm)
+			$(arch_variant_cflags) \
+			-include $(android_config_h) \
+			-I $(arch_include_dir)
+
+# We only need thumb interworking in cases where thumb support
+# is available in the architecture, and just to be sure, (and
+# since sometimes thumb-interwork appears to be default), we
+# specifically disable when thumb support is unavailable.
+ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
+$(combo_target)GLOBAL_CFLAGS +=	-mthumb-interwork
+else
+$(combo_target)GLOBAL_CFLAGS +=	-mno-thumb-interwork
+endif
 
 $(combo_target)GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
 
@@ -75,6 +123,15 @@
 libstdc++_root := bionic/libstdc++
 libthread_db_root := bionic/libthread_db
 
+
+## on some hosts, the target cross-compiler is not available so do not run this command
+ifneq ($(wildcard $($(combo_target)CC)),)
+# We compile with the global cflags to ensure that
+# any flags which affect libgcc are correctly taken
+# into account.
+$(combo_target)LIBGCC := $(shell $($(combo_target)CC) $($(combo_target)GLOBAL_CFLAGS) -print-libgcc-file-name)
+endif
+
 # unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
 # symlinks located in out/ to point to the appropriate kernel
 # headers. see 'config/kernel_headers.make' for more details
diff --git a/core/find-jdk-tools-jar.sh b/core/find-jdk-tools-jar.sh
index 091eae4..4c40627 100755
--- a/core/find-jdk-tools-jar.sh
+++ b/core/find-jdk-tools-jar.sh
@@ -1,7 +1,11 @@
-if [[ "x$ANDROID_JAVA_HOME" != x && -e $ANDROID_JAVA_HOME/lib/tools.jar ]] ; then
+if [ "x$ANDROID_JAVA_HOME" != x ] && [ -e "$ANDROID_JAVA_HOME/lib/tools.jar" ] ; then
     echo $ANDROID_JAVA_HOME/lib/tools.jar
 else
     JAVAC=$(which javac)
+    if [ -z "$JAVAC" ] ; then
+	echo "Please-install-JDK-5.0,-update-12-or-higher,-which-you-can-download-from-java.sun.com"
+	exit 1
+    fi
     while [ -L $JAVAC ] ; do
         LSLINE=$(ls -l $JAVAC)
         JAVAC=$(echo -n $LSLINE | sed -e "s/.* -> //")
diff --git a/core/main.mk b/core/main.mk
index bee8c7b..9a8e4d5 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -207,6 +207,16 @@
 ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
 endif
 
+## precise GC ##
+
+ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
+  # Enabling type-precise GC results in larger optimized DEX files.  The
+  # additional storage requirements for ".odex" files can cause /system
+  # to overflow on some devices, so this is configured separately for
+  # each product.
+  ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.dexopt-flags=m=y
+endif
+
 # Install an apns-conf.xml file if one's not already being installed.
 ifeq (,$(filter %:system/etc/apns-conf.xml, $(PRODUCT_COPY_FILES)))
   PRODUCT_COPY_FILES += \
@@ -218,7 +228,7 @@
 # If we're on an eng or tests build, but not on the sdk, and we have
 # a better one, use that instead.
 ifneq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
-  ifdef is_sdk_build
+  ifndef is_sdk_build
     apns_to_use := $(wildcard vendor/google/etc/apns-conf.xml)
     ifneq ($(strip $(apns_to_use)),)
       PRODUCT_COPY_FILES := \
diff --git a/core/multi_prebuilt.mk b/core/multi_prebuilt.mk
index 707af10..738a88d 100644
--- a/core/multi_prebuilt.mk
+++ b/core/multi_prebuilt.mk
@@ -53,13 +53,13 @@
     $(eval LOCAL_MODULE := $(word 1,$(tw))) \
     $(eval LOCAL_SRC_FILES := $(word 2,$(tw))) \
    , \
-    $(eval LOCAL_MODULE := $(basename $(t))) \
+    $(eval LOCAL_MODULE := $(basename $(notdir $(t)))) \
     $(eval LOCAL_SRC_FILES := $(t)) \
    ) \
   $(if $(6), \
     $(eval LOCAL_BUILT_MODULE_STEM := $(6)) \
    , \
-    $(eval LOCAL_BUILT_MODULE_STEM := $(LOCAL_SRC_FILES)) \
+    $(eval LOCAL_BUILT_MODULE_STEM := $(notdir $(LOCAL_SRC_FILES))) \
    ) \
   $(eval LOCAL_MODULE_SUFFIX := $(suffix $(LOCAL_SRC_FILES))) \
   $(eval include $(BUILD_PREBUILT)) \
diff --git a/core/notice_files.mk b/core/notice_files.mk
index 24295c7..fd76d51 100644
--- a/core/notice_files.mk
+++ b/core/notice_files.mk
@@ -20,12 +20,19 @@
     # We can't use xxx_OUT_STATIC_LIBRARIES because it points into
     # device-obj or host-obj.
     module_installed_filename := \
-    	$(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
+        $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
   else
     ifeq ($(LOCAL_MODULE_CLASS),JAVA_LIBRARIES)
       # Stick the static java libraries with the regular java libraries.
+      module_leaf := $(notdir $(LOCAL_BUILT_MODULE))
+      # javalib.jar is the default name for the build module (and isn't meaningful)
+      # If that's what we have, substitute the module name instead.  These files
+      # aren't included on the device, so this name is synthetic anyway.
+      ifeq ($(module_leaf),javalib.jar)
+        module_leaf := $(LOCAL_MODULE).jar
+      endif
       module_installed_filename := \
-	  $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE))
+          $(patsubst $(PRODUCT_OUT)%,%,$($(my_prefix)OUT_JAVA_LIBRARIES))/$(module_leaf)
     else
       $(error Cannot determine where to install NOTICE file for $(LOCAL_MODULE))
     endif # JAVA_LIBRARIES
diff --git a/core/pathmap.mk b/core/pathmap.mk
index e281b9d..992e3ef 100644
--- a/core/pathmap.mk
+++ b/core/pathmap.mk
@@ -28,8 +28,8 @@
 #
 pathmap_INCL := \
     bluedroid:system/bluetooth/bluedroid/include \
-    bluez-libs:external/bluez/libs/include \
-    bluez-utils:external/bluez/utils \
+    bluez:external/bluetooth/bluez \
+    glib:external/bluetooth/glib \
     bootloader:bootable/bootloader/legacy/include \
     corecg:external/skia/include/core \
     dbus:external/dbus \
diff --git a/core/prelink-linux-arm.map b/core/prelink-linux-arm.map
index 8925e22..13d30e2 100644
--- a/core/prelink-linux-arm.map
+++ b/core/prelink-linux-arm.map
@@ -27,7 +27,7 @@
 liba2dp.so              0xAEE00000
 audio.so                0xAED00000
 input.so                0xAEC00000
-libhcid.so              0xAEB00000
+libbluetoothd.so        0xAEB00000
 libbluedroid.so         0xAEA00000
 libbluetooth.so         0xAE900000
 libdbus.so              0xAE800000
@@ -52,6 +52,7 @@
 libpixelflinger.so      0xACF00000
 libcorecg.so            0xACE00000
 libsurfaceflinger.so    0xACD00000
+libGLES_android.so      0xACC80000
 libagl.so               0xACC00000
 
 libGLESv1_CM.so         0xACB00000
@@ -60,6 +61,8 @@
 libOpenVGU_CM.so        0xAC800000
 libEGL.so               0xAC700000
 
+libacc.so               0xAC600000
+
 libexif.so              0xAC500000
 libui.so                0xAC400000
 libsgl.so               0xAC000000
@@ -80,6 +83,7 @@
 libsqlite.so            0xAAC00000
 libexpat.so             0xAAB00000
 libwebcore.so           0xAA000000
+libbinder.so            0xA9D80000
 libutils.so             0xA9D00000
 libcameraservice.so     0xA9C80000
 libhardware.so          0xA9C70000
diff --git a/core/product.mk b/core/product.mk
index adc81c3..a9a24d2 100644
--- a/core/product.mk
+++ b/core/product.mk
@@ -68,7 +68,8 @@
     PRODUCT_SDK_ADDON_NAME \
     PRODUCT_SDK_ADDON_COPY_FILES \
     PRODUCT_SDK_ADDON_COPY_MODULES \
-    PRODUCT_SDK_ADDON_DOC_MODULE
+    PRODUCT_SDK_ADDON_DOC_MODULE \
+    PRODUCT_DEFAULT_WIFI_CHANNELS
 
 define dump-product
 $(info ==== $(1) ====)\
diff --git a/core/product_config.mk b/core/product_config.mk
index 7cfa5f4..3237801 100644
--- a/core/product_config.mk
+++ b/core/product_config.mk
@@ -214,6 +214,9 @@
   PRODUCT_MANUFACTURER := unknown
 endif
 
+PRODUCT_DEFAULT_WIFI_CHANNELS := \
+	$(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_DEFAULT_WIFI_CHANNELS))
+
 # Which policy should this product use
 PRODUCT_POLICY := $(strip $(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_POLICY))
 
diff --git a/core/version_defaults.mk b/core/version_defaults.mk
index ca8487f..bbcbb51 100644
--- a/core/version_defaults.mk
+++ b/core/version_defaults.mk
@@ -41,7 +41,7 @@
   # which is the version that we reveal to the end user.
   # Update this value when the platform version changes (rather
   # than overriding it somewhere else).  Can be an arbitrary string.
-  PLATFORM_VERSION := Donut
+  PLATFORM_VERSION := Eclair
 endif
 
 ifeq "" "$(PLATFORM_SDK_VERSION)"
@@ -57,9 +57,9 @@
 endif
 
 ifeq "" "$(PLATFORM_VERSION_CODENAME)"
-  # If the build is not a final release build, then this is the current
-  # development code-name.  If this is a final release build, it is simply "REL".
-  PLATFORM_VERSION_CODENAME := Donut
+  # This is the current development code-name, if the build is not a final
+  # release build.  If this is a final release build, it is simply "REL".
+  PLATFORM_VERSION_CODENAME := Eclair
 endif
 
 ifeq "" "$(DEFAULT_APP_TARGET_SDK)"
diff --git a/envsetup.sh b/envsetup.sh
index 541bb11..81163c4 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -634,6 +634,7 @@
                     ARGS="$ARGS showcommands"
                 else
                     echo "No Android.mk in $DIR."
+                    return 1
                 fi
             fi
         done
@@ -718,14 +719,14 @@
     Darwin)
         function sgrep()
         {
-            find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n "$@"
+            find -E . -type f -iregex '.*\.(c|h|cpp|S|java|xml|sh|mk)' -print0 | xargs -0 grep --color -n "$@"
         }
 
         ;;
     *)
         function sgrep()
         {
-            find . -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\)' -print0 | xargs -0 grep --color -n "$@"
+            find . -type f -iregex '.*\.\(c\|h\|cpp\|S\|java\|xml\|sh\|mk\)' -print0 | xargs -0 grep --color -n "$@"
         }
         ;;
 esac
diff --git a/history/cupcake.txt b/history/cupcake.txt
new file mode 100644
index 0000000..7947f93
--- /dev/null
+++ b/history/cupcake.txt
@@ -0,0 +1,1103 @@
+Cupcake auto-import at change 127436, Jan 22 2009.
+
+(cd bionic && git checkout c2f23bb1cdea20fc5e8e5b8101d9d0bd6d14b74b)
+(cd bootable/bootloader/legacy && git checkout d08c9e9444e2fb688ca4d3c4d807ba69c680fb3c)
+(cd bootable/diskinstaller && git checkout a2bb8bf00fbd01859e2475fc36fc6fa070e6eaa9)
+(cd bootable/recovery && git checkout 6d12e0d6f8fe05ebd6b0210fed00e0ff874a3d70)
+(cd build && git checkout b33e7b0cb085a1937c1a2e5b81eb78d6059bf6bc)
+(cd dalvik && git checkout cd18d5743d1957b1c1f57c0abe7ea28187c63a9f)
+(cd development && git checkout 2f3ec0146063b7bed40ff4f41c73407cebdc71fc)
+(cd external/aes && git checkout 17e798f9d2c0a804b5dcac6ee4b2bc1eee66e3b2)
+(cd external/apache-http && git checkout 4e30c8f9f80e5bd40fd8f018760b01a80b16b8c3)
+(cd external/bison && git checkout b7f2b4d529ee03ee0e4172cc06e7cd973bd9bef5)
+(cd external/bluez && git checkout dbbd69e74e390449430a6c357a098fd345fde2ed)
+(cd external/bsdiff && git checkout 03874566c6f74e11d030fa2c534b3dd5a06721af)
+(cd external/bzip2 && git checkout d78fa13a44d08622d61d0df71e731de77021dcf1)
+(cd external/clearsilver && git checkout b651aeec8a719c9f639ef710423e29463123d4f6)
+(cd external/dbus && git checkout ed0821c6a30852d02d05ce85d4ad4a567ff8a3da)
+(cd external/dhcpcd && git checkout 4c5a5fb53bccceff331bae70f748bf9b4609fe0a)
+(cd external/dosfstools && git checkout c936fe75ee33b6cbc46e6124679d9a1d5d471663)
+(cd external/dropbear && git checkout 1abbfe5d373a44e7e0525fb7971ef0e00955f2e4)
+(cd external/e2fsprogs && git checkout 0bc54db4f9a9aab8225f5107a712c4bbbe34f79c)
+(cd external/elfcopy && git checkout 8d6d7ea32d2e40489fa8be26618167fb6e2dfb40)
+(cd external/elfutils && git checkout ee6008996aa701ad2a50d5d6b1529c9e2c2724c1)
+(cd external/embunit && git checkout 225a86217dd274aea51b1e442568e7aec43a74e9)
+(cd external/emma && git checkout 725ce5e17f431acc3b549f87464a7883f98adf66)
+(cd external/esd && git checkout 7ef614b2e0ad463c3454cd9ba1052c2964e14596)
+(cd external/expat && git checkout da44bf784a2b6acb5df7f40b32c0d4b563fba3ed)
+(cd external/fdlibm && git checkout 74aa530c6ca9c2f10a0e3635b4211f1438b972b2)
+(cd external/freetype && git checkout b36db06baca4c030538565e01b8264971c9b69f8)
+(cd external/gdata && git checkout e784ba4a104f64d1f57dad38ff76764b5718bea0)
+(cd external/genext2fs && git checkout f4a0b4d282a1718ac6e3fff10d02aa877e294324)
+(cd external/giflib && git checkout ff6a75e423d8333c6657e4a66494e0bc9ed34385)
+(cd external/googleclient && git checkout d3974b69b023cb38541d1870ad5c35e4b2ea2c35)
+(cd external/grub && git checkout 1650e5296608be8925d9831310c9ad3595fd6869)
+(cd external/icu4c && git checkout 80865003e90c51ddd5f1e5e1be5ebc1add6af188)
+(cd external/iptables && git checkout 10a1e8d1003257d408c77662fc5ce6470a19b245)
+(cd external/jdiff && git checkout 0e7cb56de28fb496d69a1dd1907388b2076224d6)
+(cd external/jhead && git checkout 9705c3e3c1b19598026449c303d54cdc485f35a9)
+(cd external/jpeg && git checkout 9175dba76b0c31e0870fe074d476650cf258071c)
+(cd external/libffi && git checkout 8c63892438fbb7ef754e55c60220dd02e7c8fd70)
+(cd external/libpcap && git checkout 23295e59cff9c04be154ede6afad16bc9fe385cf)
+(cd external/libpng && git checkout 78ac9384d6ca0067d77b843b70bbdd828bb738df)
+(cd external/libxml2 && git checkout 2c905f99793b8da7f02349aa69fc01cba533f935)
+(cd external/netcat && git checkout 6fc2e7182a81d3665e5233a6555fc6c1960b6b8a)
+(cd external/netperf && git checkout acbeb739a2260972afbd58233fc8939fe5014e3c)
+(cd external/neven && git checkout dfddd36f99a6e11ca3b0107b49f35c623203c8f2)
+(cd external/opencore && git checkout 7a7c607909568a2a1b561023be821919bdb9d578)
+(cd external/openssl && git checkout 499ee9f31d10290f510c2f3785b6abe1314993ec)
+(cd external/oprofile && git checkout b0a81c270584f10323634816b6e5e19711690233)
+(cd external/ping && git checkout 8a5b42ad26815061053bc553b2d04fcbbce5f9d0)
+(cd external/ppp && git checkout 9d869087afe63b8506a367aaeb2008459c823ecf)
+(cd external/protobuf && git checkout 2f1917b2d9754d6288e8de2739469bf719438388)
+(cd external/qemu && git checkout 7a5cb2bf2725afddd4ff9ede151063d23b849d94)
+(cd external/safe-iop && git checkout a625f2f303bd1e1eb8287d82075fa9a240296167)
+(cd external/skia && git checkout 07051704de661e1c4e0fffc4f486afb60110f7e6)
+(cd external/sonivox && git checkout 372b906dec9f897dc04ba3bbd00c908bb2304e95)
+(cd external/sqlite && git checkout 60a965a2f8a63d7704130d867458495a324801e1)
+(cd external/srec && git checkout 00743dcf9e86961f3867b81ef81022040c821f18)
+(cd external/strace && git checkout 67670f6420d064f0b0f54ab2cf2f07752dcc35c7)
+(cd external/tagsoup && git checkout 4bb395b502d0c2495f7a5d226ccf7f06f53dea38)
+(cd external/tcpdump && git checkout f3ccc4ec63431539743f1155a60192a40f6bec24)
+(cd external/tinyxml && git checkout 600ebb441039bcb8a0340df016c6685a688b7647)
+(cd external/tremor && git checkout 0ad0141e864cfbb130db4f22e279d421832e7336)
+(cd external/webkit && git checkout 3607268bbf57cd3af1bb2d67e956821fb8e3c9ec)
+(cd external/wpa_supplicant && git checkout 17800c6dac7ac53c2b348151274071a4cc6e4318)
+(cd external/xdelta3 && git checkout 65fb2b2df617551c42d9bdf7b5bc88168ce6f1ff)
+(cd external/yaffs2 && git checkout d333fc232d7e5ae3370080d5d6f7d88ea9c6b3a1)
+(cd external/zlib && git checkout e860c69e014c1dfed34cf4ee808d200648205f2a)
+(cd frameworks/base && git checkout 94cbba0933e50d593c1c462cff698dd3387ba95b)
+(cd frameworks/opt/com.google.android && git checkout 95252a12ffcf47582ab8b68a35a996ef50cdb523)
+(cd frameworks/opt/com.google.android.googlelogin && git checkout 8f1d2acbab346be5c40d06d24a07bc169ad9c60e)
+(cd frameworks/policies/base && git checkout 880754ac4766e622367a6d65304c0b4176260e0d)
+(cd hardware/libhardware && git checkout 37156b8db0bee9a0e77160a40483d0fad0409bd4)
+(cd hardware/libhardware_legacy && git checkout 5af6317f266c0f7792f6a2fa1c2061f61529aab7)
+(cd hardware/ril && git checkout 154a2efc9b75de255cf9c3916d9d778c445df2ae)
+(cd kernel && git checkout 3c625cce51fadd88b75db8b6766de38f4ce7deaf)
+(cd packages/apps/AlarmClock && git checkout c8208f9f6ff76479da3b1eb0cedbd5500b8be1f4)
+(cd packages/apps/Browser && git checkout c3996145a81b44e27b7fad251e460ccf9c4a5d61)
+(cd packages/apps/Calculator && git checkout d3f7cb4de21253fbeeec0cf4b680bd79e6e62e8a)
+(cd packages/apps/Calendar && git checkout 1c94a74857db16dec676dc16e1ff58f9a4d0385c)
+(cd packages/apps/Camera && git checkout bf1c107ea0bbe8d80769b70d8e9b50dbf8cfcc09)
+(cd packages/apps/Contacts && git checkout cbe59e173d0baf73e98b12ac889ca17172677121)
+(cd packages/apps/Email && git checkout 6f463987544260a770b9203bd412fb665c59d0f9)
+(cd packages/apps/GoogleSearch && git checkout 2134a0d22132a8e68b6914ce466aa2acf28c244a)
+(cd packages/apps/HTMLViewer && git checkout ae36e6ba1ad74a7eb844a41c6c0fc1ecd3c66467)
+(cd packages/apps/IM && git checkout ad1551cc24ebeffda11932c1d2cae0cf1b69a854)
+(cd packages/apps/Launcher && git checkout a3673051acdee1f88b68ffc3a39f0db8529009ff)
+(cd packages/apps/Mms && git checkout 2d9959fea0cfea5fca09d139b66b1fa2cd45bf49)
+(cd packages/apps/Music && git checkout fa0935a617742fe1545bb65202d2b93af8985b6a)
+(cd packages/apps/PackageInstaller && git checkout 3a1faab9685bd0fc39ea7bf5bdc7237805d09c58)
+(cd packages/apps/Phone && git checkout 4974565b48789d5b12c302a846fc090e67039647)
+(cd packages/apps/Settings && git checkout c0a8abbb4f423c0aaa66a1e09bafd4b845837537)
+(cd packages/apps/SoundRecorder && git checkout eb2e5e6a43c0756e9d3e149f46f6a504747175f2)
+(cd packages/apps/Stk && git checkout 4e63a901fb044d270868b4f3abc8abb20d011230)
+(cd packages/apps/Sync && git checkout d8aa470c7fea6a43e269da78e1a2b8c14fb40c70)
+(cd packages/apps/Updater && git checkout 9e0cd9b717f546609ec155f6be3764554ede6408)
+(cd packages/apps/VoiceDialer && git checkout 1ab735e15b6855beabd22f5b87d497f83b3b5b6a)
+(cd packages/providers/CalendarProvider && git checkout 3690a0259f2c62501a47c9a4ecd007f1c1cc599a)
+(cd packages/providers/ContactsProvider && git checkout ef7f8057050027ce57424b69dc697d4127ffc37d)
+(cd packages/providers/DownloadProvider && git checkout b7f50f86e1f424ab05dc8154c3fabbfb3ecd4c47)
+(cd packages/providers/DrmProvider && git checkout 7f08c3d1582a2195fd7b28a3157dedd975230d8b)
+(cd packages/providers/GoogleContactsProvider && git checkout 1a6c0f279fe754b041290768bfa753e5f58e43ad)
+(cd packages/providers/GoogleSubscribedFeedsProvider && git checkout 88f4be5460c130c048e5017999a80275d71a88d6)
+(cd packages/providers/ImProvider && git checkout 8d4eb986192e7682c770449e0695d23d954a5691)
+(cd packages/providers/MediaProvider && git checkout ef92b4dc14a5f8093cb1b58888c213a867504afa)
+(cd packages/providers/TelephonyProvider && git checkout 62f78e4e0ae991f0df285488a1af382bd5105483)
+(cd prebuilt && git checkout 4ef7c54fb1bdfbd5e93d631c7f76ea216ab2d375)
+(cd system/bluetooth && git checkout 36658369459e22152cce54bd1c0660d71a270947)
+(cd system/core && git checkout 4a4c9f6f98055918f1ebff06b3cc1ed622c058fe)
+(cd system/extras && git checkout 1d68e595e72f955a8cd12f59825943ea71daf7d5)
+(cd system/wlan/ti && git checkout 6ff408df1efe9981f20ab8ce6ec36d6ff6f034dc)
+
+Change 127102
+
+	Allow different "Settings > About phone > Contributors" for different products.  The product-specific contributors.{html,css} are copied to /system/etc, and the Contributors activity loads it from there.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/build/core/product.mk#4 edit
+... //branches/cupcake/android/build/core/product_config.mk#9 edit
+
+--------
+
+Change 127106
+
+	This removes the patch intended to fix this webkit bug
+	http://bugs.webkit.org/show_bug.cgi?id=16512
+	(orginally reported by this bug: http://b/issue?id=954816)
+	
+	The original bug can no longer be reproduced in webkit.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLAppletElement.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLEmbedElement.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLFormElement.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLFormElement.h#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLImageElement.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLImageElement.h#2 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLObjectElement.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLPlugInElement.cpp#2 edit
+... //branches/cupcake/android/external/webkit/WebCore/html/HTMLPlugInElement.h#2 edit
+
+--------
+
+Change 127112
+
+	Added RemoteViews.setOnClickPendingIntent() that connects onClick events to launch PendingIntents.  Also exposed un-@hide RemoteViews.setImageViewBitmap().  Also added @RemoteView annotation to Button and ImageButton to allow them across the RemoteView boundary, and added tests to verify this happens.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/api/current.xml#105 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/widget/Button.java#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/widget/ImageButton.java#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/widget/RemoteViews.java#2 edit
+... //branches/cupcake/android/frameworks/base/tests/FrameworkTest/res/layout/remote_view_test_good.xml#2 edit
+... //branches/cupcake/android/frameworks/base/tests/FrameworkTest/tests/src/com/android/frameworktest/view/RemoteViewsActivityTest.java#2 edit
+
+--------
+
+Change 127115
+
+	Fix bug where UMS wouldn't enable properly
+	
+
+Affected files ...
+
+... //branches/cupcake/android/system/core/vold/volmgr.c#8 edit
+
+--------
+
+Change 127120
+
+	Automated rollback of changelist 127102.
+
+
+Affected files ...
+
+... //branches/cupcake/android/build/core/product.mk#5 edit
+... //branches/cupcake/android/build/core/product_config.mk#10 edit
+
+--------
+
+Change 127126
+
+	Add back auto space on candidate selection.
+	Delay key feedback display.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/inputmethodservice/KeyboardView.java#9 edit
+
+--------
+
+Change 127129
+
+	Remove the call to is.reset(). This allows callers to embedded data after the encoded bitmap and be able to retrieve it.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/graphics/java/android/graphics/BitmapFactory.java#2 edit
+
+--------
+
+Change 127134
+
+	add copyPixelsFromBuffer, to allow developers to write pixels values with no format or alpha transformations that accompany using setPixels.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/development/samples/ApiDemos/AndroidManifest.xml#7 edit
+... //branches/cupcake/android/development/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapPixels.java#1 add
+... //branches/cupcake/android/frameworks/base/api/current.xml#106 edit
+... //branches/cupcake/android/frameworks/base/core/jni/android/graphics/Bitmap.cpp#4 edit
+... //branches/cupcake/android/frameworks/base/graphics/java/android/graphics/Bitmap.java#2 edit
+
+--------
+
+Change 127136
+
+	Fix power consumption notification when driver is removed
+	
+
+Affected files ...
+
+... //branches/cupcake/android/system/wlan/ti/sta_dk_4_0_4_32/pform/linux/src/esta_drv.c#10 edit
+
+--------
+
+Change 127138
+
+	Enable building dosfstools for all non simulator builds
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/dosfstools/src/Android.mk#2 edit
+
+--------
+
+Change 127142
+
+	Use a single button for both the mode indicator and the recording indicator.
+	This makes for a smoother user experience when using the trackball, as the
+	focus highlight stays on the button when you start recording.
+	
+	(Bonus: the code's shorter too. We just switch the button's drawable rather than
+	hiding one button and showing another.)
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Camera/res/layout/video_camera.xml#8 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/VideoCamera.java#25 edit
+
+--------
+
+Change 127144
+
+	Fix problem that would leave the "now playing" list empty when removing the currently playing song from it.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Music/src/com/android/music/TrackBrowserActivity.java#13 edit
+
+--------
+
+Change 127146
+
+	Handle NPE when search is invoked but no suggestions are
+	provided.  Also, add a field
+	that was missing in the parceling of SearchableInfo.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/app/SearchDialog.java#20 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/server/search/SearchableInfo.java#6 edit
+
+--------
+
+Change 127147
+
+	Bug fix - SET UP CALL - sending confirmation result twice. TERMINAL RESPONSE is not needed.
+	
+	When the user's confirmation result is handled by Telephony->StkService, returns immediately after calling CommandInterface.handleCallSetupRequestFromSim(). This will insure that the no termainl response is going to be send.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/telephony/java/com/android/internal/telephony/gsm/stk/StkService.java#2 edit
+
+--------
+
+Change 127155
+
+	Don't switch back to video preview mode when bringing up the menu, except if
+	we're recording.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/VideoCamera.java#26 edit
+
+--------
+
+Change 127159
+
+	Change back button behavior when ping-ponging between the still-image camera and
+	the single-image gallery view. Now going from the gallery back to the still-image
+	camera acts like a "back" as far as the activity stack is concerned.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/MenuHelper.java#19 edit
+
+--------
+
+Change 127165
+
+	Added a test that attempts to access a nonexistent static field.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/tests/064-field-access/expected.txt#2 edit
+... //branches/cupcake/android/dalvik/tests/064-field-access/src/GetNonexistent.java#1 add
+... //branches/cupcake/android/dalvik/tests/064-field-access/src/Holder.java#1 add
+... //branches/cupcake/android/dalvik/tests/064-field-access/src/Main.java#2 edit
+... //branches/cupcake/android/dalvik/tests/064-field-access/src2/Holder.java#1 add
+
+--------
+
+Change 127170
+
+	Setup a place to put IMF/IME sample activities. The idea is to try to
+	create situations that we want to test the IMF/IME against, that aren't
+	necessarily represented well by the existing applications. Include an
+	input type test for starters.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/Android.mk#1 add
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/AndroidManifest.xml#1 add
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/res/layout/sample_edit_text.xml#1 add
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/res/values/strings.xml#1 add
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/src/com/android/imftest/samples/InputTypeActivity.java#1 add
+
+--------
+
+Change 127176
+
+	Expose API in SDK to remove cache files
+	
+	Add a new public api to free cache in PackageManager. The call back is via a pending intent.
+	Rename the api to freeStorage and change usage in other places.
+	Add a new unit test.
+	Remove DeviceMemoryMonitor from code base.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/cmds/installd/commands.c#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/ApplicationContext.java#5 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/content/pm/IPackageManager.aidl#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/content/pm/PackageManager.java#4 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/DeviceMemoryMonitor.java#2 delete
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/DeviceStorageMonitorService.java#2 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/PackageManagerService.java#6 edit
+... //branches/cupcake/android/frameworks/base/test-runner/android/test/mock/MockPackageManager.java#3 edit
+... //branches/cupcake/android/frameworks/base/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java#3 edit
+... //branches/cupcake/android/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java#5 edit
+
+--------
+
+Change 127180
+
+	Fix TextAppearanceSpan parceling to write in the same
+	order as it reads.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/text/TextUtils.java#7 edit
+
+--------
+
+Change 127182
+
+	* General cleanup
+	* Switch to supporting split file (one for platform, one for product
+	  specific entries).
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Email/res/xml/providers.xml#7 edit
+... //branches/cupcake/android/packages/apps/Email/res/xml/providers_product.xml#1 branch
+... //branches/cupcake/android/packages/apps/Email/src/com/android/email/activity/setup/AccountSetupBasics.java#7 integrate
+
+--------
+
+Change 127194
+
+	Fix bug (The camera preview is not in full screen after using the trackball to select the "capture" button).  Also clean up the transitions between fullscreen and non-fullscreen a bit by animating the status bar.
+	Still not perfect, of course. :(
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/view/WindowManagerPolicy.java#2 edit
+... //branches/cupcake/android/frameworks/base/core/res/res/anim/status_bar_enter.xml#1 add
+... //branches/cupcake/android/frameworks/base/core/res/res/anim/status_bar_exit.xml#1 add
+... //branches/cupcake/android/frameworks/base/core/res/res/values/styles.xml#9 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/WindowManagerService.java#14 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/status/StatusBarService.java#7 edit
+... //branches/cupcake/android/frameworks/policies/base/mid/com/android/internal/policy/impl/MidWindowManager.java#2 edit
+... //branches/cupcake/android/frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java#12 edit
+
+--------
+
+Change 127197
+
+	Add broadcast intents for the following new external media events:
+	    - Volume is being disk checked
+	    - Volume is blank (no partition table or no supported filesystems)
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/content/Intent.java#11 edit
+
+--------
+
+Change 127200
+
+	Camera work:
+	+ Define a standard, albeit currently @hidden, intent-extra for specifying that
+	  videos and/or pictures should be written to a given content URI.
+	  (This had been the hard-coded string "output". We kept the value the same so
+	  that any in-the-wild applications that use this extra will continue to work.)
+	
+	+ Add the ability to specify that a video is recorded to a given content URI.
+	  (Because we can't actually do this at the video camera level yet, we cheat
+	   and implement this feature using a copy-and-delete-the-original-video-file.)
+	
+	+ Add a test to the MarkTest scratch app to test out this new ability.
+	
+	+ Remove mention of the "pick" intent from the camera and video camera activities.
+	  (This was a copy-and-paste error from when the code was originally copied from
+	   the image gallery activities.)
+	
+	+ Wrap use of MediaMetadataRetriever in try / catch clauses because the
+	  media metadata retriever was observed to throw a runtime exception if it was
+	  given a garbage video file.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/provider/MediaStore.java#16 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/Camera.java#30 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/CropImage.java#4 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/ImageManager.java#13 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/MenuHelper.java#20 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/VideoCamera.java#27 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/Wallpaper.java#4 edit
+
+--------
+
+Change 127225
+
+	Ensure that the fingerprint doesn't contain spaces.
+	
+	Strip the BoardConfig-defined variable.
+	
+	Fail if the fingerprint doesn't contain exactly one word.
+	
+	Remove an old check that is no longer necessary.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/build/core/Makefile#14 edit
+... //branches/cupcake/android/build/core/main.mk#18 edit
+
+--------
+
+Change 127245
+
+	Temporarily disable A2DP and force audio hardware when any audio streams are ringtones, alarms or notifications.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/libs/audioflinger/AudioFlinger.cpp#18 edit
+... //branches/cupcake/android/frameworks/base/libs/audioflinger/AudioFlinger.h#10 edit
+
+--------
+
+Change 127247
+
+	When the dom changes, preserve the focus unless the frame structure has
+	changed. The old test was too conservative, and required that the old and
+	new pointers match. With this change, only require that frame's position
+	in the parent hierarchy match.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/webkit/WebKit/android/nav/CachedFrame.cpp#3 edit
+... //branches/cupcake/android/external/webkit/WebKit/android/nav/CachedFrame.h#3 edit
+... //branches/cupcake/android/external/webkit/WebKit/android/nav/WebView.cpp#21 edit
+
+--------
+
+Change 127249
+
+	Log a better message when rejecting a class because we're not able
+	to resolve a static field.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/vm/analysis/CodeVerify.c#12 edit
+
+--------
+
+Change 127250
+
+	Added a unique serial number to class objects.  This allows classes
+	to be uniquely identified in a world where the GC can move objects
+	around.
+	
+	This replaces the hprofSerialNumber that was included when
+	WITH_HPROF_STACK was defined.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/vm/Globals.h#4 edit
+... //branches/cupcake/android/dalvik/vm/hprof/HprofClass.c#2 edit
+... //branches/cupcake/android/dalvik/vm/hprof/HprofStackFrame.c#2 edit
+... //branches/cupcake/android/dalvik/vm/mterp/common/asm-constants.h#3 edit
+... //branches/cupcake/android/dalvik/vm/oo/Array.c#3 edit
+... //branches/cupcake/android/dalvik/vm/oo/Class.c#5 edit
+... //branches/cupcake/android/dalvik/vm/oo/Class.h#2 edit
+... //branches/cupcake/android/dalvik/vm/oo/Object.h#3 edit
+... //branches/cupcake/android/dalvik/vm/reflect/Proxy.c#3 edit
+
+--------
+
+Change 127253
+
+	Convert microseconds to milliseconds before formatting
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/os/BatteryStats.java#4 edit
+
+--------
+
+Change 127254
+
+	Print a log message rather than a stack trace when the shared prefs file is unreadable
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/app/ApplicationContext.java#6 edit
+
+--------
+
+Change 127259
+
+	Integration of the latest EAS and JET engine updates from Sonivox.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/sonivox/arm-wt-22k/host_src/jet.h#3 edit
+... //branches/cupcake/android/external/sonivox/arm-wt-22k/lib_src/eas_midi.c#2 edit
+... //branches/cupcake/android/external/sonivox/arm-wt-22k/lib_src/jet.c#3 edit
+... //branches/cupcake/android/external/sonivox/arm-wt-22k/lib_src/jet_data.h#2 edit
+
+--------
+
+Change 127263
+
+	Adds the User dictionary settings, available via Settings > Locale and text > User dictionary, allowing you to see or add words to the user dictionary.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Settings/AndroidManifest.xml#14 edit
+... //branches/cupcake/android/packages/apps/Settings/res/drawable/ic_menu_add.png#1 add
+... //branches/cupcake/android/packages/apps/Settings/res/layout/dialog_edittext.xml#1 add
+... //branches/cupcake/android/packages/apps/Settings/res/layout/list_content_with_empty_view.xml#1 add
+... //branches/cupcake/android/packages/apps/Settings/res/values/strings.xml#26 edit
+... //branches/cupcake/android/packages/apps/Settings/res/xml/language_settings.xml#3 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/UserDictionarySettings.java#1 add
+
+--------
+
+Change 127270
+
+	Buffer the response data even for redirects. If the redirect turns out
+	to be null, use the buffered data in webcore.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/webkit/LoadListener.java#5 edit
+
+--------
+
+Change 127272
+
+	This removes the quarter second delay when passing a set focus message from
+	WebView to WebCore. 
+	
+	The delay was originally added in March of 2008 to help reduce the burden
+	on WebCore when moving across several items with the trackball in quick secession.
+	By delaying the event, it is easier to detect if there are subsequent events
+	before the first is executed, allowing intermediate JavaScript, layout, and 
+	display list builds to be deferred until the user is finished navigating.
+	
+	Since March, JavaScript and display list building are substantially faster.
+	The old design makes it difficult to keep items in order since not all events
+	(e.g. resizing the window) are delayed the same.
+	
+	This change preserves the code that discards navigation events as WebCore
+	falls behind -- the change causes only the first trackball movement to make
+	it to WebCore, where with the delay, the first movement may be ignored.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/webkit/WebView.java#29 edit
+
+--------
+
+Change 127273
+
+	Pass the mouse click through to webkit, even if the node hit isn't valid.
+	
+	The node and frame are captured when the nav cache is built. They may not
+	still be around when a later mouse click is processed. If either are not
+	valid, skip special code that deals with image maps and menu lists, but
+	still pass the mouse click to the main frame.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/webkit/WebKit/android/jni/WebViewCore.cpp#16 edit
+
+--------
+
+Change 127274
+
+	Overhaul bonding API.
+	
+	- listBondings() is now listBonds() and uses cached values in the system
+	  server
+	- hasBonding() is now getBondState() and uses cached values in the system
+	  server. It also returns an integer state code now to include the
+	  in-progress state (BOND_BONDING)
+	- createBonding() is now createBond() and no longer has an async callback.
+	  Use intents instead.
+	- BONDING_CREATED_ACTION / BONDING_REMOVED_ACTION are now
+	  BOND_STATE_CHANGED_ACTION with state codes, and result codes.
+	- Introduced BluetoothDevice.BOND_RESULT_* result codes so the UI can pick
+	  a nicer error message. TODO(jasonparekh): update the UI to use these result codes.
+	- Removed Setttings App PAIRING_STATUS in favor of BluetoothDevice.BOND_*
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/bluetooth/BluetoothDevice.java#4 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/bluetooth/BluetoothIntent.java#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/bluetooth/IBluetoothDevice.aidl#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/bluetooth/IBluetoothDeviceCallback.aidl#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/server/BluetoothA2dpService.java#9 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/server/BluetoothDeviceService.java#6 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/server/BluetoothEventLoop.java#4 edit
+... //branches/cupcake/android/frameworks/base/core/jni/android_server_BluetoothDeviceService.cpp#2 edit
+... //branches/cupcake/android/frameworks/base/core/jni/android_server_BluetoothEventLoop.cpp#6 edit
+... //branches/cupcake/android/packages/apps/Phone/src/com/android/phone/BluetoothHeadsetService.java#6 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothEventRedirector.java#3 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/bluetooth/LocalBluetoothDevice.java#8 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/bluetooth/LocalBluetoothDeviceManager.java#6 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/bluetooth/LocalBluetoothManager.java#5 edit
+... //branches/cupcake/android/packages/apps/Settings/src/com/android/settings/bluetooth/SettingsBtStatus.java#2 edit
+
+--------
+
+Change 127275
+
+	Added class name to "pure-abstract" warning.  Added a test case that
+	exercises "conversion" of the superclass declaration from concrete to
+	abstract.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/expected.txt#2 edit
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/info.txt#2 edit
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/src/AbstractBase.java#2 edit
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/src/ConcreteSub.java#2 edit
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/src/ConcreteSub2.java#1 add
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/src/Main.java#2 edit
+... //branches/cupcake/android/dalvik/tests/032-concrete-sub/src2/AbstractBase.java#2 edit
+... //branches/cupcake/android/dalvik/vm/analysis/DexOptimize.c#5 edit
+
+--------
+
+Change 127278
+
+	Bug 1555561: Make the EditTexts in the "Add Bookmark" dialog
+	single-line so they don't stretch and mess up the layout.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Browser/res/layout/browser_add_bookmark.xml#2 edit
+
+--------
+
+Change 127282
+
+	   Fix build.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/tests/AndroidTests/src/com/android/unit_tests/BluetoothTest.java#3 edit
+
+--------
+
+Change 127283
+
+	   Clean up some old cruft.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/system/core/init/devices.c#7 edit
+
+--------
+
+Change 127285
+
+	sync with demetrius r75
+	allow to build with scalar==fixed again
+	remove some unneeded SK_BUILD_FOR_MAC tests
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/skia/include/core/SkBitmap.h#2 edit
+... //branches/cupcake/android/external/skia/src/core/SkFloatBits.cpp#2 edit
+... //branches/cupcake/android/external/skia/src/core/SkGraphics.cpp#4 edit
+... //branches/cupcake/android/external/skia/src/core/SkMath.cpp#3 edit
+... //branches/cupcake/android/external/skia/src/ports/SkFontHost_mac.cpp#3 edit
+
+--------
+
+Change 127289
+
+	Increase MMS size to 1MB.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/core/java/android/provider/Settings.java#28 edit
+... //branches/cupcake/android/packages/apps/Mms/src/com/android/mms/model/CarrierContentRestriction.java#2 edit
+... //branches/cupcake/android/packages/apps/Mms/src/com/android/mms/model/ContentRestriction.java#2 edit
+... //branches/cupcake/android/packages/apps/Mms/src/com/android/mms/model/SlideshowModel.java#2 edit
+
+--------
+
+Change 127297
+
+	Fixing Socket Spec
+	Fixing a Bug where SecurityManager.checkConnect is called with the
+	host name instead of the host address as it is specified and
+	implemented by the RI.
+	Reenabling comented out code in InetAddress.getLocalHost()
+	Fixed an error in InetAddress.equals() where we were not adhering to the spec.
+	Applied some fixes copied from harmony to not have to deal with dem later.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/libcore/luni/src/main/java/java/net/InetAddress.java#5 edit
+... //branches/cupcake/android/dalvik/libcore/luni/src/main/java/java/net/NegCacheElement.java#3 edit
+... //branches/cupcake/android/dalvik/libcore/luni/src/main/java/java/net/NegativeCache.java#3 edit
+... //branches/cupcake/android/dalvik/libcore/luni/src/main/java/java/net/Socket.java#3 edit
+
+--------
+
+Change 127310
+
+	Fix ToggleButton. A previous change I made was based on a false assumption about how LayerDrawable works. A LayerDrawable *adds* the padding of all of its layers, each layer being translated by the padding of the layer below it. Surprising, but necessary to make widgets like ToggleButton work.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/graphics/java/android/graphics/drawable/LayerDrawable.java#4 edit
+
+--------
+
+Change 127315
+
+	Implement "IME: Add transactions to InputConnection".  Also change the background dim amount, which I forgot to include with my previous check-in. :)
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/api/current.xml#107 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/view/inputmethod/InputConnection.java#11 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/view/inputmethod/InputConnectionWrapper.java#9 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/view/inputmethod/InputMethodManager.java#22 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/widget/TextView.java#23 edit
+... //branches/cupcake/android/frameworks/base/core/java/com/android/internal/view/IInputConnectionWrapper.java#11 edit
+... //branches/cupcake/android/frameworks/base/core/java/com/android/internal/view/IInputContext.aidl#10 edit
+... //branches/cupcake/android/frameworks/base/core/java/com/android/internal/view/InputConnectionWrapper.java#10 edit
+... //branches/cupcake/android/frameworks/base/core/java/com/android/internal/widget/EditableInputConnection.java#11 edit
+... //branches/cupcake/android/frameworks/base/core/res/res/values/themes.xml#6 edit
+
+--------
+
+Change 127338
+
+	Reset variables in bluetooth_start() to fix intermittent glitches resuming A2DP after standby.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/bluez/utils/audio/liba2dp.c#12 edit
+
+--------
+
+Change 127341
+
+	ButtonActivity - test to see if softkeyboard responds correctly to button activity.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/AndroidManifest.xml#2 edit
+... //branches/cupcake/android/frameworks/base/tests/ImfTest/src/com/android/imftest/samples/ButtonActivity.java#1 add
+
+--------
+
+Change 127342
+
+	   Make GadgetService get the list of gadgets by querying the package
+	   manager, and having a configuration xml file instead of hard coding
+	   it.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/api/current.xml#108 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/gadget/GadgetManager.java#2 edit
+... //branches/cupcake/android/frameworks/base/core/java/com/android/internal/gadget/IGadgetService.aidl#2 edit
+... //branches/cupcake/android/frameworks/base/core/res/res/values/attrs.xml#32 edit
+... //branches/cupcake/android/frameworks/base/core/res/res/values/public.xml#32 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/GadgetService.java#2 edit
+... //branches/cupcake/android/frameworks/base/tests/GadgetHost/AndroidManifest.xml#2 edit
+... //branches/cupcake/android/frameworks/base/tests/GadgetHost/src/com/android/gadgethost/GadgetHostActivity.java#2 edit
+... //branches/cupcake/android/frameworks/base/tests/GadgetHost/src/com/android/gadgethost/GadgetPickActivity.java#2 edit
+
+--------
+
+Change 127344
+
+	Make sure the music service also stops itself if it got killed and restarted by the system.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Music/src/com/android/music/MediaPlaybackService.java#10 edit
+
+--------
+
+Change 127347
+
+	   add the gadget_info xml file
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/tests/GadgetHost/res/xml/gadget_info.xml#1 add
+
+--------
+
+Change 127356
+
+	Submit rightly signed 64-bit driver
+	
+
+Affected files ...
+
+... //branches/cupcake/android/development/host/windows/prebuilt/usb/driver_amd_64/androidusb.sys#3 edit
+... //branches/cupcake/android/development/host/windows/prebuilt/usb/driver_amd_64/androidusba64.cat#3 edit
+
+--------
+
+Change 127362
+
+	Use mmap to load speech model files.  Use const.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/srec/srec/clib/log_add.h#2 edit
+... //branches/cupcake/android/external/srec/srec/clib/swimodel.c#2 edit
+... //branches/cupcake/android/external/srec/srec/clib/voc_read.c#2 edit
+... //branches/cupcake/android/external/srec/srec/crec/c47mulsp.c#2 edit
+... //branches/cupcake/android/external/srec/srec/crec/get_fram.c#2 edit
+... //branches/cupcake/android/external/srec/srec/crec/srec.c#2 edit
+... //branches/cupcake/android/external/srec/srec/include/c42mul.h#2 edit
+... //branches/cupcake/android/external/srec/srec/include/hmmlib.h#2 edit
+... //branches/cupcake/android/external/srec/srec/include/simapi.h#2 edit
+... //branches/cupcake/android/external/srec/srec/include/srec.h#2 edit
+... //branches/cupcake/android/external/srec/srec/include/swimodel.h#2 edit
+... //branches/cupcake/android/external/srec/tools/grxmlcompile/grph.h#2 edit
+
+--------
+
+Change 127363
+
+	Bug 1547138: Add copyright headers to translated strings files.
+	Don't generate files that don't actually contain any translations.
+	Check in code for generating translation console flat-file format.
+	
+
+Affected files ...
+
+[list deleted]
+
+--------
+
+Change 127371
+
+	Clean up termination of the GPS network thread.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/location/java/com/android/internal/location/GpsLocationProvider.java#6 edit
+
+--------
+
+Change 127377
+
+	Introduce a new Activity callback, onUserLeaving(), that is invoked whenever the user initiates an action that causes the activity to be moved away from being frontmost.
+	
+	Any code that starts activities "silently," without the user having prompted the action, should supply the new Intent.FLAG_ACTIVITY_NO_USER_ACTION flag when calling startActivity().  This instructs the Activity Manager that this focus change is not due to user activity, suppressing the onUserLeaving() callback.  This is important to preserve the reliability of the onUserLeaving() callback indicating a specific user choice to navigate to the new activity.
+	
+	The two known apps in the tree that forcibly start activities without user activity have also been updated to use this new Intent flag:  Phone and AlarmClock.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/frameworks/base/api/current.xml#109 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/Activity.java#9 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/ActivityThread.java#6 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/ApplicationThreadNative.java#3 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/IApplicationThread.java#3 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/app/Instrumentation.java#3 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/content/Intent.java#12 edit
+... //branches/cupcake/android/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java#11 edit
+... //branches/cupcake/android/packages/apps/AlarmClock/src/com/android/alarmclock/AlarmReceiver.java#4 edit
+... //branches/cupcake/android/packages/apps/Phone/src/com/android/phone/PhoneApp.java#6 edit
+
+--------
+
+Change 127385
+
+	marking bookmarks as untranslatable
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Browser/res/values/strings.xml#15 integrate
+
+--------
+
+Change 127387
+
+	Test case to make sure we don't reuse the "this" register in
+	instance methods.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/dalvik/dx/tests/110-dex-preserve-this/Blort.java#1 add
+... //branches/cupcake/android/dalvik/dx/tests/110-dex-preserve-this/expected.txt#1 add
+... //branches/cupcake/android/dalvik/dx/tests/110-dex-preserve-this/info.txt#1 add
+... //branches/cupcake/android/dalvik/dx/tests/110-dex-preserve-this/run#1 add
+
+--------
+
+Change 127392
+
+	update the 'update-audio.sh' script that is used to upload a new prebuilt version
+	of the QEMU audio sub-system for Linux.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/qemu/Makefile.android#10 integrate
+... //branches/cupcake/android/external/qemu/distrib/update-audio.sh#2 edit
+... //branches/cupcake/android/prebuilt/linux-x86/emulator/libqemu-audio.a#2 edit
+
+--------
+
+Change 127400
+
+	Fix the problem where the build would break looking for "@".
+	
+	built_ota_tools should have been a list of files, not a list
+	of commands to build those files.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/build/core/Makefile#15 edit
+
+--------
+
+Change 127406
+
+	Fix bug (Bottom/Menu portion of the screen is appearing black).  There were a bunch of issues with deciding when to show the IME window, and a big issue in the sample keyboard IME with when it was handing starting of input (it would only work if the keyboard view had been created).
+	
+
+Affected files ...
+
+... //branches/cupcake/android/development/samples/SoftKeyboard/src/com/example/android/softkeyboard/SoftKeyboard.java#6 edit
+... //branches/cupcake/android/frameworks/base/core/java/android/inputmethodservice/InputMethodService.java#21 edit
+
+--------
+
+Change 127412
+
+	   Fix timer subtraction when there is > 1 second difference.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/bluez/utils/audio/liba2dp.c#13 edit
+
+--------
+
+Change 127433
+
+	Fix Mac build of the emulator
+	
+
+Affected files ...
+
+... //branches/cupcake/android/external/qemu/Makefile.android#11 edit
+
+--------
+
+Change 127436
+
+	 Camera: Create a subclass of ImageView that can be used as a camera button.
+	+ Clients can register for notification when the button is pressed, optionally clicked,
+	and released.
+	     - note that you can press a button, then move your finger off of it before releasing,
+	       in which case ther would be a pressed and a released notification, but no clicked
+	       notification.
+	     - The reason we want to do this is so we can emulate the physical camera button, which
+	       has focus down, optional camera down-and-up, and focus up events.
+	+ The pressed, clicked, and released notifications are delivered in that order, both for
+	  touch presses and for trackball/dpad presses. (This was tricky because the UI
+	  framework delivers the underlying notifications in a different order for the two
+	  types of input.)
+	+ Use the new shutter button in the still-image camera. We don't yet need it in the
+	  video camera, but it could be used there as well.
+	
+
+Affected files ...
+
+... //branches/cupcake/android/packages/apps/Camera/res/layout/camera.xml#16 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/Camera.java#31 edit
+... //branches/cupcake/android/packages/apps/Camera/src/com/android/camera/ShutterButton.java#1 add
+
+--------
+
diff --git a/target/product/core.mk b/target/product/core.mk
index 204345e..8cf6b24 100644
--- a/target/product/core.mk
+++ b/target/product/core.mk
@@ -3,7 +3,8 @@
 PRODUCT_DEVICE :=
 PRODUCT_POLICY := android.policy_phone
 PRODUCT_PROPERTY_OVERRIDES := \
-    ro.config.notification_sound=F1_New_SMS.ogg
+    ro.config.notification_sound=F1_New_SMS.ogg \
+    ro.config.alarm_alert=Alarm_Classic.ogg
 
 PRODUCT_PACKAGES := \
     framework-res \
diff --git a/target/product/generic_with_google.mk b/target/product/generic_with_google.mk
index dddbbb7..57a2b86 100644
--- a/target/product/generic_with_google.mk
+++ b/target/product/generic_with_google.mk
@@ -7,10 +7,12 @@
     GoogleContactsProvider \
     GoogleSubscribedFeedsProvider \
     com.google.android.gtalkservice \
+    com.google.android.datamessaging \
     com.google.android.maps
 
 PRODUCT_COPY_FILES := \
     vendor/google/frameworks/maps/com.google.android.maps.xml:system/etc/permissions/com.google.android.maps.xml \
+    vendor/google/frameworks/datamessaging/com.google.android.datamessaging.xml:system/etc/permissions/com.google.android.datamessaging.xml \
     vendor/google/apps/GTalkService/com.google.android.gtalkservice.xml:system/etc/permissions/com.google.android.gtalkservice.xml
 
 
diff --git a/target/product/min_dev.mk b/target/product/min_dev.mk
index 005af70..056c2b8 100644
--- a/target/product/min_dev.mk
+++ b/target/product/min_dev.mk
@@ -1,7 +1,8 @@
 
 PRODUCT_POLICY := android.policy_phone
 PRODUCT_PROPERTY_OVERRIDES := \
-    ro.config.notification_sound=F1_New_SMS.ogg
+    ro.config.notification_sound=F1_New_SMS.ogg \
+    ro.config.alarm_alert=Alarm_Classic.ogg
 PRODUCT_BRAND := generic
 PRODUCT_NAME := min_dev
 PRODUCT_DEVICE := generic
diff --git a/tools/apriori/prelinkmap.c b/tools/apriori/prelinkmap.c
index 739c181..9fb00e4 100644
--- a/tools/apriori/prelinkmap.c
+++ b/tools/apriori/prelinkmap.c
@@ -7,11 +7,14 @@
 
 typedef struct mapentry mapentry;
 
+#define MAX_ALIASES 10
+
 struct mapentry
 {
     mapentry *next;
     unsigned base;
-    char name[0];
+    char *names[MAX_ALIASES];
+    int num_names;
 };
 
 static mapentry *maplist = 0;
@@ -22,14 +25,13 @@
 */
 
 #define PRELINK_MIN 0x90000000
-#define PRELINK_MAX 0xB0000000
+#define PRELINK_MAX 0xBFFFFFFF
 
 void pm_init(const char *file)
 {
     unsigned line = 0;
     char buf[256];
     char *x;
-    unsigned n;
     FILE *fp;
     mapentry *me;
     unsigned last = -1UL;
@@ -65,26 +67,52 @@
             continue;
         }
         
-        n = strtoul(x, 0, 16);
-        /* Note that this is not the only bounds check.  If a library's size
-           exceeds its slot as defined in the prelink map, the prelinker will
-           exit with an error.  See pm_report_library_size_in_memory().
-        */
-        FAILIF((n < PRELINK_MIN) || (n > PRELINK_MAX),
-               "%s:%d base 0x%08x out of range.\n",
-               file, line, n);
-        
-        me = malloc(sizeof(mapentry) + strlen(buf) + 1);
-        FAILIF(me == NULL, "Out of memory parsing %s\n", file);
+        if (isalpha(*x)) {
+            /* Assume that this is an alias, and look through the list of
+               already-installed libraries.
+            */
+            me = maplist;
+            while(me) {
+                /* The strlen() call ignores the newline at the end of x */
+                if (!strncmp(me->names[0], x, strlen(me->names[0]))) {
+                    PRINT("Aliasing library %s to %s at %08x\n",
+                          buf, x, me->base);
+                    break;
+                }
+                me = me->next;
+            }
+            FAILIF(!me, "Nonexistent alias %s -> %s\n", buf, x);
+        }
+        else {
+            unsigned n = strtoul(x, 0, 16);
+            /* Note that this is not the only bounds check.  If a library's
+               size exceeds its slot as defined in the prelink map, the
+               prelinker will exit with an error.  See
+               pm_report_library_size_in_memory().
+            */
+            FAILIF((n < PRELINK_MIN) || (n > PRELINK_MAX),
+                   "%s:%d base 0x%08x out of range.\n",
+                   file, line, n);
 
-        FAILIF(last <= n, "The prelink map is not in descending order "
-               "at entry %s (%08x)!\n", buf, n);
-        last = n;
-        
-        me->base = n;
-        strcpy(me->name, buf);
-        me->next = maplist;
-        maplist = me;        
+            me = malloc(sizeof(mapentry));
+            FAILIF(me == NULL, "Out of memory parsing %s\n", file);
+
+            FAILIF(last <= n, "The prelink map is not in descending order "
+                   "at entry %s (%08x)!\n", buf, n);
+            last = n;
+
+            me->base = n;
+            me->next = maplist;
+            me->num_names = 0;
+            maplist = me;
+        }
+
+        FAILIF(me->num_names >= MAX_ALIASES,
+               "Too many aliases for library %s, maximum is %d.\n",
+               me->names[0],
+               MAX_ALIASES);
+        me->names[me->num_names] = strdup(buf);
+        me->num_names++;
     }
 
     fclose(fp);
@@ -99,41 +127,44 @@
 {
     char *x;
     mapentry *me;
+    int n;
     
     x = strrchr(name,'/');
     if(x) name = x+1;
 
     for(me = maplist; me; me = me->next){
-        if(!strcmp(name, me->name)) {
-            off_t slot = me->next ? me->next->base : PRELINK_MAX;
-            slot -= me->base;
-            FAILIF(fsize > slot,
-                   "prelink map error: library %s@0x%08x is too big "
-                   "at %lld bytes, it runs %lld bytes into "
-                   "library %s@0x%08x!\n",
-                   me->name, me->base, fsize, fsize - slot,
-                   me->next->name, me->next->base);
-            break;
+        for (n = 0; n < me->num_names; n++) {
+            if(!strcmp(name, me->names[n])) {
+                off_t slot = me->next ? me->next->base : PRELINK_MAX;
+                slot -= me->base;
+                FAILIF(fsize > slot,
+                       "prelink map error: library %s@0x%08x is too big "
+                       "at %lld bytes, it runs %lld bytes into "
+                       "library %s@0x%08x!\n",
+                       me->names[0], me->base, fsize, fsize - slot,
+                       me->next->names[0], me->next->base);
+                return;
+            }
         }
     }
     
-    FAILIF(!me,"library '%s' not in prelink map\n", name);
+    FAILIF(1, "library '%s' not in prelink map\n", name);
 }
 
 unsigned pm_get_next_link_address(const char *lookup_name)
 {
     char *x;
     mapentry *me;
+    int n;
     
     x = strrchr(lookup_name,'/');
     if(x) lookup_name = x+1;
     
-    for(me = maplist; me; me = me->next){
-        if(!strcmp(lookup_name, me->name)) {
-            return me->base;
-        }
-    }
-    
-    FAILIF(1==1,"library '%s' not in prelink map\n", lookup_name);
+    for(me = maplist; me; me = me->next)
+        for (n = 0; n < me->num_names; n++)
+            if(!strcmp(lookup_name, me->names[n]))
+                return me->base;
+
+    FAILIF(1, "library '%s' not in prelink map\n", lookup_name);
     return 0;
 }
diff --git a/tools/atree/files.cpp b/tools/atree/files.cpp
index c675ab7..d4866d4 100644
--- a/tools/atree/files.cpp
+++ b/tools/atree/files.cpp
@@ -7,6 +7,8 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <fnmatch.h>
+#include <string.h>
+#include <stdlib.h>
 
 static bool
 is_comment_line(const char* p)
diff --git a/tools/atree/fs.cpp b/tools/atree/fs.cpp
index 022bd8c..00f44c2 100644
--- a/tools/atree/fs.cpp
+++ b/tools/atree/fs.cpp
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <string.h>
 #include <host/CopyFile.h>
 
 using namespace std;
diff --git a/tools/buildinfo.sh b/tools/buildinfo.sh
index 5c738a2..af5aa47 100755
--- a/tools/buildinfo.sh
+++ b/tools/buildinfo.sh
@@ -24,6 +24,7 @@
 echo "ro.product.manufacturer=$PRODUCT_MANUFACTURER"
 echo "ro.product.locale.language=$PRODUCT_DEFAULT_LANGUAGE"
 echo "ro.product.locale.region=$PRODUCT_DEFAULT_REGION"
+echo "ro.wifi.channels=$PRODUCT_DEFAULT_WIFI_CHANNELS"
 echo "ro.board.platform=$TARGET_BOARD_PLATFORM"
 
 echo "# ro.build.product is obsolete; use ro.product.device"
diff --git a/tools/droiddoc/src/ClassInfo.java b/tools/droiddoc/src/ClassInfo.java
index 2fd65e0..f397a83 100644
--- a/tools/droiddoc/src/ClassInfo.java
+++ b/tools/droiddoc/src/ClassInfo.java
@@ -378,7 +378,7 @@
 
     public TagInfo[] deprecatedTags()
     {
-        // should we also do the interfaces?
+        // Should we also do the interfaces?
         return comment().deprecatedTags();
     }
 
diff --git a/tools/findleaves.sh b/tools/findleaves.sh
index 7cc0fa7..dafa1d8 100755
--- a/tools/findleaves.sh
+++ b/tools/findleaves.sh
@@ -86,7 +86,7 @@
 # Print out all files that match, as long as the path isn't explicitly
 # pruned. This will print out extraneous results from directories whose
 # parents have a match. These are filtered out by the awk script below.
-find "${@:0:$nargs}" $findargs -type f -name "$filename" -print |
+find -L "${@:1:$nargs-1}" $findargs -type f -name "$filename" -print |
 
 # Only pass along the directory of each match.
 sed -e 's/\/[^\/]*$/\//' |
diff --git a/tools/zipalign/Android.mk b/tools/zipalign/Android.mk
index e23b699..f90a31c 100644
--- a/tools/zipalign/Android.mk
+++ b/tools/zipalign/Android.mk
@@ -8,7 +8,9 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := \
-	ZipAlign.cpp
+	ZipAlign.cpp \
+	ZipEntry.cpp \
+	ZipFile.cpp
 
 LOCAL_C_INCLUDES += external/zlib
 
diff --git a/tools/zipalign/ZipAlign.cpp b/tools/zipalign/ZipAlign.cpp
index 058f9ed..eab2f04 100644
--- a/tools/zipalign/ZipAlign.cpp
+++ b/tools/zipalign/ZipAlign.cpp
@@ -16,7 +16,7 @@
 /*
  * Zip alignment tool
  */
-#include "utils/ZipFile.h"
+#include "ZipFile.h"
 
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/tools/zipalign/ZipEntry.cpp b/tools/zipalign/ZipEntry.cpp
new file mode 100644
index 0000000..bed0333
--- /dev/null
+++ b/tools/zipalign/ZipEntry.cpp
@@ -0,0 +1,696 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Access to entries in a Zip archive.
+//
+
+#define LOG_TAG "zip"
+
+#include "ZipEntry.h"
+#include <utils/Log.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+using namespace android;
+
+/*
+ * Initialize a new ZipEntry structure from a FILE* positioned at a
+ * CentralDirectoryEntry.
+ *
+ * On exit, the file pointer will be at the start of the next CDE or
+ * at the EOCD.
+ */
+status_t ZipEntry::initFromCDE(FILE* fp)
+{
+    status_t result;
+    long posn;
+    bool hasDD;
+
+    //LOGV("initFromCDE ---\n");
+
+    /* read the CDE */
+    result = mCDE.read(fp);
+    if (result != NO_ERROR) {
+        LOGD("mCDE.read failed\n");
+        return result;
+    }
+
+    //mCDE.dump();
+
+    /* using the info in the CDE, go load up the LFH */
+    posn = ftell(fp);
+    if (fseek(fp, mCDE.mLocalHeaderRelOffset, SEEK_SET) != 0) {
+        LOGD("local header seek failed (%ld)\n",
+            mCDE.mLocalHeaderRelOffset);
+        return UNKNOWN_ERROR;
+    }
+
+    result = mLFH.read(fp);
+    if (result != NO_ERROR) {
+        LOGD("mLFH.read failed\n");
+        return result;
+    }
+
+    if (fseek(fp, posn, SEEK_SET) != 0)
+        return UNKNOWN_ERROR;
+
+    //mLFH.dump();
+
+    /*
+     * We *might* need to read the Data Descriptor at this point and
+     * integrate it into the LFH.  If this bit is set, the CRC-32,
+     * compressed size, and uncompressed size will be zero.  In practice
+     * these seem to be rare.
+     */
+    hasDD = (mLFH.mGPBitFlag & kUsesDataDescr) != 0;
+    if (hasDD) {
+        // do something clever
+        //LOGD("+++ has data descriptor\n");
+    }
+
+    /*
+     * Sanity-check the LFH.  Note that this will fail if the "kUsesDataDescr"
+     * flag is set, because the LFH is incomplete.  (Not a problem, since we
+     * prefer the CDE values.)
+     */
+    if (!hasDD && !compareHeaders()) {
+        LOGW("WARNING: header mismatch\n");
+        // keep going?
+    }
+
+    /*
+     * If the mVersionToExtract is greater than 20, we may have an
+     * issue unpacking the record -- could be encrypted, compressed
+     * with something we don't support, or use Zip64 extensions.  We
+     * can defer worrying about that to when we're extracting data.
+     */
+
+    return NO_ERROR;
+}
+
+/*
+ * Initialize a new entry.  Pass in the file name and an optional comment.
+ *
+ * Initializes the CDE and the LFH.
+ */
+void ZipEntry::initNew(const char* fileName, const char* comment)
+{
+    assert(fileName != NULL && *fileName != '\0');  // name required
+
+    /* most fields are properly initialized by constructor */
+    mCDE.mVersionMadeBy = kDefaultMadeBy;
+    mCDE.mVersionToExtract = kDefaultVersion;
+    mCDE.mCompressionMethod = kCompressStored;
+    mCDE.mFileNameLength = strlen(fileName);
+    if (comment != NULL)
+        mCDE.mFileCommentLength = strlen(comment);
+    mCDE.mExternalAttrs = 0x81b60020;   // matches what WinZip does
+
+    if (mCDE.mFileNameLength > 0) {
+        mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
+        strcpy((char*) mCDE.mFileName, fileName);
+    }
+    if (mCDE.mFileCommentLength > 0) {
+        /* TODO: stop assuming null-terminated ASCII here? */
+        mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
+        strcpy((char*) mCDE.mFileComment, comment);
+    }
+
+    copyCDEtoLFH();
+}
+
+/*
+ * Initialize a new entry, starting with the ZipEntry from a different
+ * archive.
+ *
+ * Initializes the CDE and the LFH.
+ */
+status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
+    const ZipEntry* pEntry)
+{
+    /*
+     * Copy everything in the CDE over, then fix up the hairy bits.
+     */
+    memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
+
+    if (mCDE.mFileNameLength > 0) {
+        mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
+        if (mCDE.mFileName == NULL)
+            return NO_MEMORY;
+        strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
+    }
+    if (mCDE.mFileCommentLength > 0) {
+        mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
+        if (mCDE.mFileComment == NULL)
+            return NO_MEMORY;
+        strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
+    }
+    if (mCDE.mExtraFieldLength > 0) {
+        /* we null-terminate this, though it may not be a string */
+        mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
+        if (mCDE.mExtraField == NULL)
+            return NO_MEMORY;
+        memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
+            mCDE.mExtraFieldLength+1);
+    }
+
+    /* construct the LFH from the CDE */
+    copyCDEtoLFH();
+
+    /*
+     * The LFH "extra" field is independent of the CDE "extra", so we
+     * handle it here.
+     */
+    assert(mLFH.mExtraField == NULL);
+    mLFH.mExtraFieldLength = pEntry->mLFH.mExtraFieldLength;
+    if (mLFH.mExtraFieldLength > 0) {
+        mLFH.mExtraField = new unsigned char[mLFH.mExtraFieldLength+1];
+        if (mLFH.mExtraField == NULL)
+            return NO_MEMORY;
+        memcpy(mLFH.mExtraField, pEntry->mLFH.mExtraField,
+            mLFH.mExtraFieldLength+1);
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Insert pad bytes in the LFH by tweaking the "extra" field.  This will
+ * potentially confuse something that put "extra" data in here earlier,
+ * but I can't find an actual problem.
+ */
+status_t ZipEntry::addPadding(int padding)
+{
+    if (padding <= 0)
+        return INVALID_OPERATION;
+
+    //LOGI("HEY: adding %d pad bytes to existing %d in %s\n",
+    //    padding, mLFH.mExtraFieldLength, mCDE.mFileName);
+
+    if (mLFH.mExtraFieldLength > 0) {
+        /* extend existing field */
+        unsigned char* newExtra;
+
+        newExtra = new unsigned char[mLFH.mExtraFieldLength + padding];
+        if (newExtra == NULL)
+            return NO_MEMORY;
+        memset(newExtra + mLFH.mExtraFieldLength, 0, padding);
+        memcpy(newExtra, mLFH.mExtraField, mLFH.mExtraFieldLength);
+
+        delete[] mLFH.mExtraField;
+        mLFH.mExtraField = newExtra;
+        mLFH.mExtraFieldLength += padding;
+    } else {
+        /* create new field */
+        mLFH.mExtraField = new unsigned char[padding];
+        memset(mLFH.mExtraField, 0, padding);
+        mLFH.mExtraFieldLength = padding;
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Set the fields in the LFH equal to the corresponding fields in the CDE.
+ *
+ * This does not touch the LFH "extra" field.
+ */
+void ZipEntry::copyCDEtoLFH(void)
+{
+    mLFH.mVersionToExtract  = mCDE.mVersionToExtract;
+    mLFH.mGPBitFlag         = mCDE.mGPBitFlag;
+    mLFH.mCompressionMethod = mCDE.mCompressionMethod;
+    mLFH.mLastModFileTime   = mCDE.mLastModFileTime;
+    mLFH.mLastModFileDate   = mCDE.mLastModFileDate;
+    mLFH.mCRC32             = mCDE.mCRC32;
+    mLFH.mCompressedSize    = mCDE.mCompressedSize;
+    mLFH.mUncompressedSize  = mCDE.mUncompressedSize;
+    mLFH.mFileNameLength    = mCDE.mFileNameLength;
+    // the "extra field" is independent
+
+    delete[] mLFH.mFileName;
+    if (mLFH.mFileNameLength > 0) {
+        mLFH.mFileName = new unsigned char[mLFH.mFileNameLength+1];
+        strcpy((char*) mLFH.mFileName, (const char*) mCDE.mFileName);
+    } else {
+        mLFH.mFileName = NULL;
+    }
+}
+
+/*
+ * Set some information about a file after we add it.
+ */
+void ZipEntry::setDataInfo(long uncompLen, long compLen, unsigned long crc32,
+    int compressionMethod)
+{
+    mCDE.mCompressionMethod = compressionMethod;
+    mCDE.mCRC32 = crc32;
+    mCDE.mCompressedSize = compLen;
+    mCDE.mUncompressedSize = uncompLen;
+    mCDE.mCompressionMethod = compressionMethod;
+    if (compressionMethod == kCompressDeflated) {
+        mCDE.mGPBitFlag |= 0x0002;      // indicates maximum compression used
+    }
+    copyCDEtoLFH();
+}
+
+/*
+ * See if the data in mCDE and mLFH match up.  This is mostly useful for
+ * debugging these classes, but it can be used to identify damaged
+ * archives.
+ *
+ * Returns "false" if they differ.
+ */
+bool ZipEntry::compareHeaders(void) const
+{
+    if (mCDE.mVersionToExtract != mLFH.mVersionToExtract) {
+        LOGV("cmp: VersionToExtract\n");
+        return false;
+    }
+    if (mCDE.mGPBitFlag != mLFH.mGPBitFlag) {
+        LOGV("cmp: GPBitFlag\n");
+        return false;
+    }
+    if (mCDE.mCompressionMethod != mLFH.mCompressionMethod) {
+        LOGV("cmp: CompressionMethod\n");
+        return false;
+    }
+    if (mCDE.mLastModFileTime != mLFH.mLastModFileTime) {
+        LOGV("cmp: LastModFileTime\n");
+        return false;
+    }
+    if (mCDE.mLastModFileDate != mLFH.mLastModFileDate) {
+        LOGV("cmp: LastModFileDate\n");
+        return false;
+    }
+    if (mCDE.mCRC32 != mLFH.mCRC32) {
+        LOGV("cmp: CRC32\n");
+        return false;
+    }
+    if (mCDE.mCompressedSize != mLFH.mCompressedSize) {
+        LOGV("cmp: CompressedSize\n");
+        return false;
+    }
+    if (mCDE.mUncompressedSize != mLFH.mUncompressedSize) {
+        LOGV("cmp: UncompressedSize\n");
+        return false;
+    }
+    if (mCDE.mFileNameLength != mLFH.mFileNameLength) {
+        LOGV("cmp: FileNameLength\n");
+        return false;
+    }
+#if 0       // this seems to be used for padding, not real data
+    if (mCDE.mExtraFieldLength != mLFH.mExtraFieldLength) {
+        LOGV("cmp: ExtraFieldLength\n");
+        return false;
+    }
+#endif
+    if (mCDE.mFileName != NULL) {
+        if (strcmp((char*) mCDE.mFileName, (char*) mLFH.mFileName) != 0) {
+            LOGV("cmp: FileName\n");
+            return false;
+        }
+    }
+
+    return true;
+}
+
+
+/*
+ * Convert the DOS date/time stamp into a UNIX time stamp.
+ */
+time_t ZipEntry::getModWhen(void) const
+{
+    struct tm parts;
+
+    parts.tm_sec = (mCDE.mLastModFileTime & 0x001f) << 1;
+    parts.tm_min = (mCDE.mLastModFileTime & 0x07e0) >> 5;
+    parts.tm_hour = (mCDE.mLastModFileTime & 0xf800) >> 11;
+    parts.tm_mday = (mCDE.mLastModFileDate & 0x001f);
+    parts.tm_mon = ((mCDE.mLastModFileDate & 0x01e0) >> 5) -1;
+    parts.tm_year = ((mCDE.mLastModFileDate & 0xfe00) >> 9) + 80;
+    parts.tm_wday = parts.tm_yday = 0;
+    parts.tm_isdst = -1;        // DST info "not available"
+
+    return mktime(&parts);
+}
+
+/*
+ * Set the CDE/LFH timestamp from UNIX time.
+ */
+void ZipEntry::setModWhen(time_t when)
+{
+#ifdef HAVE_LOCALTIME_R
+    struct tm tmResult;
+#endif
+    time_t even;
+    unsigned short zdate, ztime;
+
+    struct tm* ptm;
+
+    /* round up to an even number of seconds */
+    even = (time_t)(((unsigned long)(when) + 1) & (~1));
+
+    /* expand */
+#ifdef HAVE_LOCALTIME_R
+    ptm = localtime_r(&even, &tmResult);
+#else
+    ptm = localtime(&even);
+#endif
+
+    int year;
+    year = ptm->tm_year;
+    if (year < 80)
+        year = 80;
+
+    zdate = (year - 80) << 9 | (ptm->tm_mon+1) << 5 | ptm->tm_mday;
+    ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1;
+
+    mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime;
+    mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;
+}
+
+
+/*
+ * ===========================================================================
+ *      ZipEntry::LocalFileHeader
+ * ===========================================================================
+ */
+
+/*
+ * Read a local file header.
+ *
+ * On entry, "fp" points to the signature at the start of the header.
+ * On exit, "fp" points to the start of data.
+ */
+status_t ZipEntry::LocalFileHeader::read(FILE* fp)
+{
+    status_t result = NO_ERROR;
+    unsigned char buf[kLFHLen];
+
+    assert(mFileName == NULL);
+    assert(mExtraField == NULL);
+
+    if (fread(buf, 1, kLFHLen, fp) != kLFHLen) {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    if (ZipEntry::getLongLE(&buf[0x00]) != kSignature) {
+        LOGD("whoops: didn't find expected signature\n");
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    mVersionToExtract = ZipEntry::getShortLE(&buf[0x04]);
+    mGPBitFlag = ZipEntry::getShortLE(&buf[0x06]);
+    mCompressionMethod = ZipEntry::getShortLE(&buf[0x08]);
+    mLastModFileTime = ZipEntry::getShortLE(&buf[0x0a]);
+    mLastModFileDate = ZipEntry::getShortLE(&buf[0x0c]);
+    mCRC32 = ZipEntry::getLongLE(&buf[0x0e]);
+    mCompressedSize = ZipEntry::getLongLE(&buf[0x12]);
+    mUncompressedSize = ZipEntry::getLongLE(&buf[0x16]);
+    mFileNameLength = ZipEntry::getShortLE(&buf[0x1a]);
+    mExtraFieldLength = ZipEntry::getShortLE(&buf[0x1c]);
+
+    // TODO: validate sizes
+
+    /* grab filename */
+    if (mFileNameLength != 0) {
+        mFileName = new unsigned char[mFileNameLength+1];
+        if (mFileName == NULL) {
+            result = NO_MEMORY;
+            goto bail;
+        }
+        if (fread(mFileName, 1, mFileNameLength, fp) != mFileNameLength) {
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        mFileName[mFileNameLength] = '\0';
+    }
+
+    /* grab extra field */
+    if (mExtraFieldLength != 0) {
+        mExtraField = new unsigned char[mExtraFieldLength+1];
+        if (mExtraField == NULL) {
+            result = NO_MEMORY;
+            goto bail;
+        }
+        if (fread(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength) {
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        mExtraField[mExtraFieldLength] = '\0';
+    }
+
+bail:
+    return result;
+}
+
+/*
+ * Write a local file header.
+ */
+status_t ZipEntry::LocalFileHeader::write(FILE* fp)
+{
+    unsigned char buf[kLFHLen];
+
+    ZipEntry::putLongLE(&buf[0x00], kSignature);
+    ZipEntry::putShortLE(&buf[0x04], mVersionToExtract);
+    ZipEntry::putShortLE(&buf[0x06], mGPBitFlag);
+    ZipEntry::putShortLE(&buf[0x08], mCompressionMethod);
+    ZipEntry::putShortLE(&buf[0x0a], mLastModFileTime);
+    ZipEntry::putShortLE(&buf[0x0c], mLastModFileDate);
+    ZipEntry::putLongLE(&buf[0x0e], mCRC32);
+    ZipEntry::putLongLE(&buf[0x12], mCompressedSize);
+    ZipEntry::putLongLE(&buf[0x16], mUncompressedSize);
+    ZipEntry::putShortLE(&buf[0x1a], mFileNameLength);
+    ZipEntry::putShortLE(&buf[0x1c], mExtraFieldLength);
+
+    if (fwrite(buf, 1, kLFHLen, fp) != kLFHLen)
+        return UNKNOWN_ERROR;
+
+    /* write filename */
+    if (mFileNameLength != 0) {
+        if (fwrite(mFileName, 1, mFileNameLength, fp) != mFileNameLength)
+            return UNKNOWN_ERROR;
+    }
+
+    /* write "extra field" */
+    if (mExtraFieldLength != 0) {
+        if (fwrite(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength)
+            return UNKNOWN_ERROR;
+    }
+
+    return NO_ERROR;
+}
+
+
+/*
+ * Dump the contents of a LocalFileHeader object.
+ */
+void ZipEntry::LocalFileHeader::dump(void) const
+{
+    LOGD(" LocalFileHeader contents:\n");
+    LOGD("  versToExt=%u gpBits=0x%04x compression=%u\n",
+        mVersionToExtract, mGPBitFlag, mCompressionMethod);
+    LOGD("  modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
+        mLastModFileTime, mLastModFileDate, mCRC32);
+    LOGD("  compressedSize=%lu uncompressedSize=%lu\n",
+        mCompressedSize, mUncompressedSize);
+    LOGD("  filenameLen=%u extraLen=%u\n",
+        mFileNameLength, mExtraFieldLength);
+    if (mFileName != NULL)
+        LOGD("  filename: '%s'\n", mFileName);
+}
+
+
+/*
+ * ===========================================================================
+ *      ZipEntry::CentralDirEntry
+ * ===========================================================================
+ */
+
+/*
+ * Read the central dir entry that appears next in the file.
+ *
+ * On entry, "fp" should be positioned on the signature bytes for the
+ * entry.  On exit, "fp" will point at the signature word for the next
+ * entry or for the EOCD.
+ */
+status_t ZipEntry::CentralDirEntry::read(FILE* fp)
+{
+    status_t result = NO_ERROR;
+    unsigned char buf[kCDELen];
+
+    /* no re-use */
+    assert(mFileName == NULL);
+    assert(mExtraField == NULL);
+    assert(mFileComment == NULL);
+
+    if (fread(buf, 1, kCDELen, fp) != kCDELen) {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    if (ZipEntry::getLongLE(&buf[0x00]) != kSignature) {
+        LOGD("Whoops: didn't find expected signature\n");
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    mVersionMadeBy = ZipEntry::getShortLE(&buf[0x04]);
+    mVersionToExtract = ZipEntry::getShortLE(&buf[0x06]);
+    mGPBitFlag = ZipEntry::getShortLE(&buf[0x08]);
+    mCompressionMethod = ZipEntry::getShortLE(&buf[0x0a]);
+    mLastModFileTime = ZipEntry::getShortLE(&buf[0x0c]);
+    mLastModFileDate = ZipEntry::getShortLE(&buf[0x0e]);
+    mCRC32 = ZipEntry::getLongLE(&buf[0x10]);
+    mCompressedSize = ZipEntry::getLongLE(&buf[0x14]);
+    mUncompressedSize = ZipEntry::getLongLE(&buf[0x18]);
+    mFileNameLength = ZipEntry::getShortLE(&buf[0x1c]);
+    mExtraFieldLength = ZipEntry::getShortLE(&buf[0x1e]);
+    mFileCommentLength = ZipEntry::getShortLE(&buf[0x20]);
+    mDiskNumberStart = ZipEntry::getShortLE(&buf[0x22]);
+    mInternalAttrs = ZipEntry::getShortLE(&buf[0x24]);
+    mExternalAttrs = ZipEntry::getLongLE(&buf[0x26]);
+    mLocalHeaderRelOffset = ZipEntry::getLongLE(&buf[0x2a]);
+
+    // TODO: validate sizes and offsets
+
+    /* grab filename */
+    if (mFileNameLength != 0) {
+        mFileName = new unsigned char[mFileNameLength+1];
+        if (mFileName == NULL) {
+            result = NO_MEMORY;
+            goto bail;
+        }
+        if (fread(mFileName, 1, mFileNameLength, fp) != mFileNameLength) {
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        mFileName[mFileNameLength] = '\0';
+    }
+
+    /* read "extra field" */
+    if (mExtraFieldLength != 0) {
+        mExtraField = new unsigned char[mExtraFieldLength+1];
+        if (mExtraField == NULL) {
+            result = NO_MEMORY;
+            goto bail;
+        }
+        if (fread(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength) {
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        mExtraField[mExtraFieldLength] = '\0';
+    }
+
+
+    /* grab comment, if any */
+    if (mFileCommentLength != 0) {
+        mFileComment = new unsigned char[mFileCommentLength+1];
+        if (mFileComment == NULL) {
+            result = NO_MEMORY;
+            goto bail;
+        }
+        if (fread(mFileComment, 1, mFileCommentLength, fp) != mFileCommentLength)
+        {
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        mFileComment[mFileCommentLength] = '\0';
+    }
+
+bail:
+    return result;
+}
+
+/*
+ * Write a central dir entry.
+ */
+status_t ZipEntry::CentralDirEntry::write(FILE* fp)
+{
+    unsigned char buf[kCDELen];
+
+    ZipEntry::putLongLE(&buf[0x00], kSignature);
+    ZipEntry::putShortLE(&buf[0x04], mVersionMadeBy);
+    ZipEntry::putShortLE(&buf[0x06], mVersionToExtract);
+    ZipEntry::putShortLE(&buf[0x08], mGPBitFlag);
+    ZipEntry::putShortLE(&buf[0x0a], mCompressionMethod);
+    ZipEntry::putShortLE(&buf[0x0c], mLastModFileTime);
+    ZipEntry::putShortLE(&buf[0x0e], mLastModFileDate);
+    ZipEntry::putLongLE(&buf[0x10], mCRC32);
+    ZipEntry::putLongLE(&buf[0x14], mCompressedSize);
+    ZipEntry::putLongLE(&buf[0x18], mUncompressedSize);
+    ZipEntry::putShortLE(&buf[0x1c], mFileNameLength);
+    ZipEntry::putShortLE(&buf[0x1e], mExtraFieldLength);
+    ZipEntry::putShortLE(&buf[0x20], mFileCommentLength);
+    ZipEntry::putShortLE(&buf[0x22], mDiskNumberStart);
+    ZipEntry::putShortLE(&buf[0x24], mInternalAttrs);
+    ZipEntry::putLongLE(&buf[0x26], mExternalAttrs);
+    ZipEntry::putLongLE(&buf[0x2a], mLocalHeaderRelOffset);
+
+    if (fwrite(buf, 1, kCDELen, fp) != kCDELen)
+        return UNKNOWN_ERROR;
+
+    /* write filename */
+    if (mFileNameLength != 0) {
+        if (fwrite(mFileName, 1, mFileNameLength, fp) != mFileNameLength)
+            return UNKNOWN_ERROR;
+    }
+
+    /* write "extra field" */
+    if (mExtraFieldLength != 0) {
+        if (fwrite(mExtraField, 1, mExtraFieldLength, fp) != mExtraFieldLength)
+            return UNKNOWN_ERROR;
+    }
+
+    /* write comment */
+    if (mFileCommentLength != 0) {
+        if (fwrite(mFileComment, 1, mFileCommentLength, fp) != mFileCommentLength)
+            return UNKNOWN_ERROR;
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Dump the contents of a CentralDirEntry object.
+ */
+void ZipEntry::CentralDirEntry::dump(void) const
+{
+    LOGD(" CentralDirEntry contents:\n");
+    LOGD("  versMadeBy=%u versToExt=%u gpBits=0x%04x compression=%u\n",
+        mVersionMadeBy, mVersionToExtract, mGPBitFlag, mCompressionMethod);
+    LOGD("  modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
+        mLastModFileTime, mLastModFileDate, mCRC32);
+    LOGD("  compressedSize=%lu uncompressedSize=%lu\n",
+        mCompressedSize, mUncompressedSize);
+    LOGD("  filenameLen=%u extraLen=%u commentLen=%u\n",
+        mFileNameLength, mExtraFieldLength, mFileCommentLength);
+    LOGD("  diskNumStart=%u intAttr=0x%04x extAttr=0x%08lx relOffset=%lu\n",
+        mDiskNumberStart, mInternalAttrs, mExternalAttrs,
+        mLocalHeaderRelOffset);
+
+    if (mFileName != NULL)
+        LOGD("  filename: '%s'\n", mFileName);
+    if (mFileComment != NULL)
+        LOGD("  comment: '%s'\n", mFileComment);
+}
+
diff --git a/tools/zipalign/ZipEntry.h b/tools/zipalign/ZipEntry.h
new file mode 100644
index 0000000..7f721b4
--- /dev/null
+++ b/tools/zipalign/ZipEntry.h
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Zip archive entries.
+//
+// The ZipEntry class is tightly meshed with the ZipFile class.
+//
+#ifndef __LIBS_ZIPENTRY_H
+#define __LIBS_ZIPENTRY_H
+
+#include <utils/Errors.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+
+namespace android {
+
+class ZipFile;
+
+/*
+ * ZipEntry objects represent a single entry in a Zip archive.
+ *
+ * You can use one of these to get or set information about an entry, but
+ * there are no functions here for accessing the data itself.  (We could
+ * tuck a pointer to the ZipFile in here for convenience, but that raises
+ * the likelihood of using ZipEntry objects after discarding the ZipFile.)
+ *
+ * File information is stored in two places: next to the file data (the Local
+ * File Header, and possibly a Data Descriptor), and at the end of the file
+ * (the Central Directory Entry).  The two must be kept in sync.
+ */
+class ZipEntry {
+public:
+    friend class ZipFile;
+
+    ZipEntry(void)
+        : mDeleted(false), mMarked(false)
+        {}
+    ~ZipEntry(void) {}
+
+    /*
+     * Returns "true" if the data is compressed.
+     */
+    bool isCompressed(void) const {
+        return mCDE.mCompressionMethod != kCompressStored;
+    }
+    int getCompressionMethod(void) const { return mCDE.mCompressionMethod; }
+
+    /*
+     * Return the uncompressed length.
+     */
+    off_t getUncompressedLen(void) const { return mCDE.mUncompressedSize; }
+
+    /*
+     * Return the compressed length.  For uncompressed data, this returns
+     * the same thing as getUncompresesdLen().
+     */
+    off_t getCompressedLen(void) const { return mCDE.mCompressedSize; }
+
+    /*
+     * Return the absolute file offset of the start of the compressed or
+     * uncompressed data.
+     */
+    off_t getFileOffset(void) const {
+        return mCDE.mLocalHeaderRelOffset +
+                LocalFileHeader::kLFHLen +
+                mLFH.mFileNameLength +
+                mLFH.mExtraFieldLength;
+    }
+
+    /*
+     * Return the data CRC.
+     */
+    unsigned long getCRC32(void) const { return mCDE.mCRC32; }
+
+    /*
+     * Return file modification time in UNIX seconds-since-epoch.
+     */
+    time_t getModWhen(void) const;
+
+    /*
+     * Return the archived file name.
+     */
+    const char* getFileName(void) const { return (const char*) mCDE.mFileName; }
+
+    /*
+     * Application-defined "mark".  Can be useful when synchronizing the
+     * contents of an archive with contents on disk.
+     */
+    bool getMarked(void) const { return mMarked; }
+    void setMarked(bool val) { mMarked = val; }
+
+    /*
+     * Some basic functions for raw data manipulation.  "LE" means
+     * Little Endian.
+     */
+    static inline unsigned short getShortLE(const unsigned char* buf) {
+        return buf[0] | (buf[1] << 8);
+    }
+    static inline unsigned long getLongLE(const unsigned char* buf) {
+        return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+    }
+    static inline void putShortLE(unsigned char* buf, short val) {
+        buf[0] = (unsigned char) val;
+        buf[1] = (unsigned char) (val >> 8);
+    }
+    static inline void putLongLE(unsigned char* buf, long val) {
+        buf[0] = (unsigned char) val;
+        buf[1] = (unsigned char) (val >> 8);
+        buf[2] = (unsigned char) (val >> 16);
+        buf[3] = (unsigned char) (val >> 24);
+    }
+
+    /* defined for Zip archives */
+    enum {
+        kCompressStored     = 0,        // no compression
+        // shrunk           = 1,
+        // reduced 1        = 2,
+        // reduced 2        = 3,
+        // reduced 3        = 4,
+        // reduced 4        = 5,
+        // imploded         = 6,
+        // tokenized        = 7,
+        kCompressDeflated   = 8,        // standard deflate
+        // Deflate64        = 9,
+        // lib imploded     = 10,
+        // reserved         = 11,
+        // bzip2            = 12,
+    };
+
+    /*
+     * Deletion flag.  If set, the entry will be removed on the next
+     * call to "flush".
+     */
+    bool getDeleted(void) const { return mDeleted; }
+
+protected:
+    /*
+     * Initialize the structure from the file, which is pointing at
+     * our Central Directory entry.
+     */
+    status_t initFromCDE(FILE* fp);
+
+    /*
+     * Initialize the structure for a new file.  We need the filename
+     * and comment so that we can properly size the LFH area.  The
+     * filename is mandatory, the comment is optional.
+     */
+    void initNew(const char* fileName, const char* comment);
+
+    /*
+     * Initialize the structure with the contents of a ZipEntry from
+     * another file.
+     */
+    status_t initFromExternal(const ZipFile* pZipFile, const ZipEntry* pEntry);
+
+    /*
+     * Add some pad bytes to the LFH.  We do this by adding or resizing
+     * the "extra" field.
+     */
+    status_t addPadding(int padding);
+
+    /*
+     * Set information about the data for this entry.
+     */
+    void setDataInfo(long uncompLen, long compLen, unsigned long crc32,
+        int compressionMethod);
+
+    /*
+     * Set the modification date.
+     */
+    void setModWhen(time_t when);
+
+    /*
+     * Return the offset of the local file header.
+     */
+    off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
+
+    /*
+     * Set the offset of the local file header, relative to the start of
+     * the current file.
+     */
+    void setLFHOffset(off_t offset) {
+        mCDE.mLocalHeaderRelOffset = (long) offset;
+    }
+
+    /* mark for deletion; used by ZipFile::remove() */
+    void setDeleted(void) { mDeleted = true; }
+
+private:
+    /* these are private and not defined */
+    ZipEntry(const ZipEntry& src);
+    ZipEntry& operator=(const ZipEntry& src);
+
+    /* returns "true" if the CDE and the LFH agree */
+    bool compareHeaders(void) const;
+    void copyCDEtoLFH(void);
+
+    bool        mDeleted;       // set if entry is pending deletion
+    bool        mMarked;        // app-defined marker
+
+    /*
+     * Every entry in the Zip archive starts off with one of these.
+     */
+    class LocalFileHeader {
+    public:
+        LocalFileHeader(void) :
+            mVersionToExtract(0),
+            mGPBitFlag(0),
+            mCompressionMethod(0),
+            mLastModFileTime(0),
+            mLastModFileDate(0),
+            mCRC32(0),
+            mCompressedSize(0),
+            mUncompressedSize(0),
+            mFileNameLength(0),
+            mExtraFieldLength(0),
+            mFileName(NULL),
+            mExtraField(NULL)
+        {}
+        virtual ~LocalFileHeader(void) {
+            delete[] mFileName;
+            delete[] mExtraField;
+        }
+
+        status_t read(FILE* fp);
+        status_t write(FILE* fp);
+
+        // unsigned long mSignature;
+        unsigned short  mVersionToExtract;
+        unsigned short  mGPBitFlag;
+        unsigned short  mCompressionMethod;
+        unsigned short  mLastModFileTime;
+        unsigned short  mLastModFileDate;
+        unsigned long   mCRC32;
+        unsigned long   mCompressedSize;
+        unsigned long   mUncompressedSize;
+        unsigned short  mFileNameLength;
+        unsigned short  mExtraFieldLength;
+        unsigned char*  mFileName;
+        unsigned char*  mExtraField;
+
+        enum {
+            kSignature      = 0x04034b50,
+            kLFHLen         = 30,       // LocalFileHdr len, excl. var fields
+        };
+
+        void dump(void) const;
+    };
+
+    /*
+     * Every entry in the Zip archive has one of these in the "central
+     * directory" at the end of the file.
+     */
+    class CentralDirEntry {
+    public:
+        CentralDirEntry(void) :
+            mVersionMadeBy(0),
+            mVersionToExtract(0),
+            mGPBitFlag(0),
+            mCompressionMethod(0),
+            mLastModFileTime(0),
+            mLastModFileDate(0),
+            mCRC32(0),
+            mCompressedSize(0),
+            mUncompressedSize(0),
+            mFileNameLength(0),
+            mExtraFieldLength(0),
+            mFileCommentLength(0),
+            mDiskNumberStart(0),
+            mInternalAttrs(0),
+            mExternalAttrs(0),
+            mLocalHeaderRelOffset(0),
+            mFileName(NULL),
+            mExtraField(NULL),
+            mFileComment(NULL)
+        {}
+        virtual ~CentralDirEntry(void) {
+            delete[] mFileName;
+            delete[] mExtraField;
+            delete[] mFileComment;
+        }
+
+        status_t read(FILE* fp);
+        status_t write(FILE* fp);
+
+        // unsigned long mSignature;
+        unsigned short  mVersionMadeBy;
+        unsigned short  mVersionToExtract;
+        unsigned short  mGPBitFlag;
+        unsigned short  mCompressionMethod;
+        unsigned short  mLastModFileTime;
+        unsigned short  mLastModFileDate;
+        unsigned long   mCRC32;
+        unsigned long   mCompressedSize;
+        unsigned long   mUncompressedSize;
+        unsigned short  mFileNameLength;
+        unsigned short  mExtraFieldLength;
+        unsigned short  mFileCommentLength;
+        unsigned short  mDiskNumberStart;
+        unsigned short  mInternalAttrs;
+        unsigned long   mExternalAttrs;
+        unsigned long   mLocalHeaderRelOffset;
+        unsigned char*  mFileName;
+        unsigned char*  mExtraField;
+        unsigned char*  mFileComment;
+
+        void dump(void) const;
+
+        enum {
+            kSignature      = 0x02014b50,
+            kCDELen         = 46,       // CentralDirEnt len, excl. var fields
+        };
+    };
+
+    enum {
+        //kDataDescriptorSignature  = 0x08074b50,   // currently unused
+        kDataDescriptorLen  = 16,           // four 32-bit fields
+
+        kDefaultVersion     = 20,           // need deflate, nothing much else
+        kDefaultMadeBy      = 0x0317,       // 03=UNIX, 17=spec v2.3
+        kUsesDataDescr      = 0x0008,       // GPBitFlag bit 3
+    };
+
+    LocalFileHeader     mLFH;
+    CentralDirEntry     mCDE;
+};
+
+}; // namespace android
+
+#endif // __LIBS_ZIPENTRY_H
diff --git a/tools/zipalign/ZipFile.cpp b/tools/zipalign/ZipFile.cpp
new file mode 100644
index 0000000..62c9383
--- /dev/null
+++ b/tools/zipalign/ZipFile.cpp
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Access to Zip archives.
+//
+
+#define LOG_TAG "zip"
+
+#include <utils/ZipUtils.h>
+#include <utils/Log.h>
+
+#include "ZipFile.h"
+
+#include <zlib.h>
+#define DEF_MEM_LEVEL 8                // normally in zutil.h?
+
+#include <memory.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <assert.h>
+
+using namespace android;
+
+/*
+ * Some environments require the "b", some choke on it.
+ */
+#define FILE_OPEN_RO        "rb"
+#define FILE_OPEN_RW        "r+b"
+#define FILE_OPEN_RW_CREATE "w+b"
+
+/* should live somewhere else? */
+static status_t errnoToStatus(int err)
+{
+    if (err == ENOENT)
+        return NAME_NOT_FOUND;
+    else if (err == EACCES)
+        return PERMISSION_DENIED;
+    else
+        return UNKNOWN_ERROR;
+}
+
+/*
+ * Open a file and parse its guts.
+ */
+status_t ZipFile::open(const char* zipFileName, int flags)
+{
+    bool newArchive = false;
+
+    assert(mZipFp == NULL);     // no reopen
+
+    if ((flags & kOpenTruncate))
+        flags |= kOpenCreate;           // trunc implies create
+
+    if ((flags & kOpenReadOnly) && (flags & kOpenReadWrite))
+        return INVALID_OPERATION;       // not both
+    if (!((flags & kOpenReadOnly) || (flags & kOpenReadWrite)))
+        return INVALID_OPERATION;       // not neither
+    if ((flags & kOpenCreate) && !(flags & kOpenReadWrite))
+        return INVALID_OPERATION;       // create requires write
+
+    if (flags & kOpenTruncate) {
+        newArchive = true;
+    } else {
+        newArchive = (access(zipFileName, F_OK) != 0);
+        if (!(flags & kOpenCreate) && newArchive) {
+            /* not creating, must already exist */
+            LOGD("File %s does not exist", zipFileName);
+            return NAME_NOT_FOUND;
+        }
+    }
+
+    /* open the file */
+    const char* openflags;
+    if (flags & kOpenReadWrite) {
+        if (newArchive)
+            openflags = FILE_OPEN_RW_CREATE;
+        else
+            openflags = FILE_OPEN_RW;
+    } else {
+        openflags = FILE_OPEN_RO;
+    }
+    mZipFp = fopen(zipFileName, openflags);
+    if (mZipFp == NULL) {
+        int err = errno;
+        LOGD("fopen failed: %d\n", err);
+        return errnoToStatus(err);
+    }
+
+    status_t result;
+    if (!newArchive) {
+        /*
+         * Load the central directory.  If that fails, then this probably
+         * isn't a Zip archive.
+         */
+        result = readCentralDir();
+    } else {
+        /*
+         * Newly-created.  The EndOfCentralDir constructor actually
+         * sets everything to be the way we want it (all zeroes).  We
+         * set mNeedCDRewrite so that we create *something* if the
+         * caller doesn't add any files.  (We could also just unlink
+         * the file if it's brand new and nothing was added, but that's
+         * probably doing more than we really should -- the user might
+         * have a need for empty zip files.)
+         */
+        mNeedCDRewrite = true;
+        result = NO_ERROR;
+    }
+
+    if (flags & kOpenReadOnly)
+        mReadOnly = true;
+    else
+        assert(!mReadOnly);
+
+    return result;
+}
+
+/*
+ * Return the Nth entry in the archive.
+ */
+ZipEntry* ZipFile::getEntryByIndex(int idx) const
+{
+    if (idx < 0 || idx >= (int) mEntries.size())
+        return NULL;
+
+    return mEntries[idx];
+}
+
+/*
+ * Find an entry by name.
+ */
+ZipEntry* ZipFile::getEntryByName(const char* fileName) const
+{
+    /*
+     * Do a stupid linear string-compare search.
+     *
+     * There are various ways to speed this up, especially since it's rare
+     * to intermingle changes to the archive with "get by name" calls.  We
+     * don't want to sort the mEntries vector itself, however, because
+     * it's used to recreate the Central Directory.
+     *
+     * (Hash table works, parallel list of pointers in sorted order is good.)
+     */
+    int idx;
+
+    for (idx = mEntries.size()-1; idx >= 0; idx--) {
+        ZipEntry* pEntry = mEntries[idx];
+        if (!pEntry->getDeleted() &&
+            strcmp(fileName, pEntry->getFileName()) == 0)
+        {
+            return pEntry;
+        }
+    }
+
+    return NULL;
+}
+
+/*
+ * Empty the mEntries vector.
+ */
+void ZipFile::discardEntries(void)
+{
+    int count = mEntries.size();
+
+    while (--count >= 0)
+        delete mEntries[count];
+
+    mEntries.clear();
+}
+
+
+/*
+ * Find the central directory and read the contents.
+ *
+ * The fun thing about ZIP archives is that they may or may not be
+ * readable from start to end.  In some cases, notably for archives
+ * that were written to stdout, the only length information is in the
+ * central directory at the end of the file.
+ *
+ * Of course, the central directory can be followed by a variable-length
+ * comment field, so we have to scan through it backwards.  The comment
+ * is at most 64K, plus we have 18 bytes for the end-of-central-dir stuff
+ * itself, plus apparently sometimes people throw random junk on the end
+ * just for the fun of it.
+ *
+ * This is all a little wobbly.  If the wrong value ends up in the EOCD
+ * area, we're hosed.  This appears to be the way that everbody handles
+ * it though, so we're in pretty good company if this fails.
+ */
+status_t ZipFile::readCentralDir(void)
+{
+    status_t result = NO_ERROR;
+    unsigned char* buf = NULL;
+    off_t fileLength, seekStart;
+    long readAmount;
+    int i;
+
+    fseek(mZipFp, 0, SEEK_END);
+    fileLength = ftell(mZipFp);
+    rewind(mZipFp);
+
+    /* too small to be a ZIP archive? */
+    if (fileLength < EndOfCentralDir::kEOCDLen) {
+        LOGD("Length is %ld -- too small\n", (long)fileLength);
+        result = INVALID_OPERATION;
+        goto bail;
+    }
+
+    buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
+    if (buf == NULL) {
+        LOGD("Failure allocating %d bytes for EOCD search",
+             EndOfCentralDir::kMaxEOCDSearch);
+        result = NO_MEMORY;
+        goto bail;
+    }
+
+    if (fileLength > EndOfCentralDir::kMaxEOCDSearch) {
+        seekStart = fileLength - EndOfCentralDir::kMaxEOCDSearch;
+        readAmount = EndOfCentralDir::kMaxEOCDSearch;
+    } else {
+        seekStart = 0;
+        readAmount = (long) fileLength;
+    }
+    if (fseek(mZipFp, seekStart, SEEK_SET) != 0) {
+        LOGD("Failure seeking to end of zip at %ld", (long) seekStart);
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    /* read the last part of the file into the buffer */
+    if (fread(buf, 1, readAmount, mZipFp) != (size_t) readAmount) {
+        LOGD("short file? wanted %ld\n", readAmount);
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    /* find the end-of-central-dir magic */
+    for (i = readAmount - 4; i >= 0; i--) {
+        if (buf[i] == 0x50 &&
+            ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
+        {
+            LOGV("+++ Found EOCD at buf+%d\n", i);
+            break;
+        }
+    }
+    if (i < 0) {
+        LOGD("EOCD not found, not Zip\n");
+        result = INVALID_OPERATION;
+        goto bail;
+    }
+
+    /* extract eocd values */
+    result = mEOCD.readBuf(buf + i, readAmount - i);
+    if (result != NO_ERROR) {
+        LOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
+        goto bail;
+    }
+    //mEOCD.dump();
+
+    if (mEOCD.mDiskNumber != 0 || mEOCD.mDiskWithCentralDir != 0 ||
+        mEOCD.mNumEntries != mEOCD.mTotalNumEntries)
+    {
+        LOGD("Archive spanning not supported\n");
+        result = INVALID_OPERATION;
+        goto bail;
+    }
+
+    /*
+     * So far so good.  "mCentralDirSize" is the size in bytes of the
+     * central directory, so we can just seek back that far to find it.
+     * We can also seek forward mCentralDirOffset bytes from the
+     * start of the file.
+     *
+     * We're not guaranteed to have the rest of the central dir in the
+     * buffer, nor are we guaranteed that the central dir will have any
+     * sort of convenient size.  We need to skip to the start of it and
+     * read the header, then the other goodies.
+     *
+     * The only thing we really need right now is the file comment, which
+     * we're hoping to preserve.
+     */
+    if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+        LOGD("Failure seeking to central dir offset %ld\n",
+             mEOCD.mCentralDirOffset);
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    /*
+     * Loop through and read the central dir entries.
+     */
+    LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
+    int entry;
+    for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
+        ZipEntry* pEntry = new ZipEntry;
+
+        result = pEntry->initFromCDE(mZipFp);
+        if (result != NO_ERROR) {
+            LOGD("initFromCDE failed\n");
+            delete pEntry;
+            goto bail;
+        }
+
+        mEntries.add(pEntry);
+    }
+
+
+    /*
+     * If all went well, we should now be back at the EOCD.
+     */
+    {
+        unsigned char checkBuf[4];
+        if (fread(checkBuf, 1, 4, mZipFp) != 4) {
+            LOGD("EOCD check read failed\n");
+            result = INVALID_OPERATION;
+            goto bail;
+        }
+        if (ZipEntry::getLongLE(checkBuf) != EndOfCentralDir::kSignature) {
+            LOGD("EOCD read check failed\n");
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+        LOGV("+++ EOCD read check passed\n");
+    }
+
+bail:
+    delete[] buf;
+    return result;
+}
+
+
+/*
+ * Add a new file to the archive.
+ *
+ * This requires creating and populating a ZipEntry structure, and copying
+ * the data into the file at the appropriate position.  The "appropriate
+ * position" is the current location of the central directory, which we
+ * casually overwrite (we can put it back later).
+ *
+ * If we were concerned about safety, we would want to make all changes
+ * in a temp file and then overwrite the original after everything was
+ * safely written.  Not really a concern for us.
+ */
+status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
+    const char* storageName, int sourceType, int compressionMethod,
+    ZipEntry** ppEntry)
+{
+    ZipEntry* pEntry = NULL;
+    status_t result = NO_ERROR;
+    long lfhPosn, startPosn, endPosn, uncompressedLen;
+    FILE* inputFp = NULL;
+    unsigned long crc;
+    time_t modWhen;
+
+    if (mReadOnly)
+        return INVALID_OPERATION;
+
+    assert(compressionMethod == ZipEntry::kCompressDeflated ||
+           compressionMethod == ZipEntry::kCompressStored);
+
+    /* make sure we're in a reasonable state */
+    assert(mZipFp != NULL);
+    assert(mEntries.size() == mEOCD.mTotalNumEntries);
+
+    /* make sure it doesn't already exist */
+    if (getEntryByName(storageName) != NULL)
+        return ALREADY_EXISTS;
+
+    if (!data) {
+        inputFp = fopen(fileName, FILE_OPEN_RO);
+        if (inputFp == NULL)
+            return errnoToStatus(errno);
+    }
+
+    if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    pEntry = new ZipEntry;
+    pEntry->initNew(storageName, NULL);
+
+    /*
+     * From here on out, failures are more interesting.
+     */
+    mNeedCDRewrite = true;
+
+    /*
+     * Write the LFH, even though it's still mostly blank.  We need it
+     * as a place-holder.  In theory the LFH isn't necessary, but in
+     * practice some utilities demand it.
+     */
+    lfhPosn = ftell(mZipFp);
+    pEntry->mLFH.write(mZipFp);
+    startPosn = ftell(mZipFp);
+
+    /*
+     * Copy the data in, possibly compressing it as we go.
+     */
+    if (sourceType == ZipEntry::kCompressStored) {
+        if (compressionMethod == ZipEntry::kCompressDeflated) {
+            bool failed = false;
+            result = compressFpToFp(mZipFp, inputFp, data, size, &crc);
+            if (result != NO_ERROR) {
+                LOGD("compression failed, storing\n");
+                failed = true;
+            } else {
+                /*
+                 * Make sure it has compressed "enough".  This probably ought
+                 * to be set through an API call, but I don't expect our
+                 * criteria to change over time.
+                 */
+                long src = inputFp ? ftell(inputFp) : size;
+                long dst = ftell(mZipFp) - startPosn;
+                if (dst + (dst / 10) > src) {
+                    LOGD("insufficient compression (src=%ld dst=%ld), storing\n",
+                        src, dst);
+                    failed = true;
+                }
+            }
+
+            if (failed) {
+                compressionMethod = ZipEntry::kCompressStored;
+                if (inputFp) rewind(inputFp);
+                fseek(mZipFp, startPosn, SEEK_SET);
+                /* fall through to kCompressStored case */
+            }
+        }
+        /* handle "no compression" request, or failed compression from above */
+        if (compressionMethod == ZipEntry::kCompressStored) {
+            if (inputFp) {
+                result = copyFpToFp(mZipFp, inputFp, &crc);
+            } else {
+                result = copyDataToFp(mZipFp, data, size, &crc);
+            }
+            if (result != NO_ERROR) {
+                // don't need to truncate; happens in CDE rewrite
+                LOGD("failed copying data in\n");
+                goto bail;
+            }
+        }
+
+        // currently seeked to end of file
+        uncompressedLen = inputFp ? ftell(inputFp) : size;
+    } else if (sourceType == ZipEntry::kCompressDeflated) {
+        /* we should support uncompressed-from-compressed, but it's not
+         * important right now */
+        assert(compressionMethod == ZipEntry::kCompressDeflated);
+
+        bool scanResult;
+        int method;
+        long compressedLen;
+
+        scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
+                        &compressedLen, &crc);
+        if (!scanResult || method != ZipEntry::kCompressDeflated) {
+            LOGD("this isn't a deflated gzip file?");
+            result = UNKNOWN_ERROR;
+            goto bail;
+        }
+
+        result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
+        if (result != NO_ERROR) {
+            LOGD("failed copying gzip data in\n");
+            goto bail;
+        }
+    } else {
+        assert(false);
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    /*
+     * We could write the "Data Descriptor", but there doesn't seem to
+     * be any point since we're going to go back and write the LFH.
+     *
+     * Update file offsets.
+     */
+    endPosn = ftell(mZipFp);            // seeked to end of compressed data
+
+    /*
+     * Success!  Fill out new values.
+     */
+    pEntry->setDataInfo(uncompressedLen, endPosn - startPosn, crc,
+        compressionMethod);
+    modWhen = getModTime(inputFp ? fileno(inputFp) : fileno(mZipFp));
+    pEntry->setModWhen(modWhen);
+    pEntry->setLFHOffset(lfhPosn);
+    mEOCD.mNumEntries++;
+    mEOCD.mTotalNumEntries++;
+    mEOCD.mCentralDirSize = 0;      // mark invalid; set by flush()
+    mEOCD.mCentralDirOffset = endPosn;
+
+    /*
+     * Go back and write the LFH.
+     */
+    if (fseek(mZipFp, lfhPosn, SEEK_SET) != 0) {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+    pEntry->mLFH.write(mZipFp);
+
+    /*
+     * Add pEntry to the list.
+     */
+    mEntries.add(pEntry);
+    if (ppEntry != NULL)
+        *ppEntry = pEntry;
+    pEntry = NULL;
+
+bail:
+    if (inputFp != NULL)
+        fclose(inputFp);
+    delete pEntry;
+    return result;
+}
+
+/*
+ * Add an entry by copying it from another zip file.  If "padding" is
+ * nonzero, the specified number of bytes will be added to the "extra"
+ * field in the header.
+ *
+ * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+ */
+status_t ZipFile::add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
+    int padding, ZipEntry** ppEntry)
+{
+    ZipEntry* pEntry = NULL;
+    status_t result;
+    long lfhPosn, endPosn;
+
+    if (mReadOnly)
+        return INVALID_OPERATION;
+
+    /* make sure we're in a reasonable state */
+    assert(mZipFp != NULL);
+    assert(mEntries.size() == mEOCD.mTotalNumEntries);
+
+    if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    pEntry = new ZipEntry;
+    if (pEntry == NULL) {
+        result = NO_MEMORY;
+        goto bail;
+    }
+
+    result = pEntry->initFromExternal(pSourceZip, pSourceEntry);
+    if (result != NO_ERROR)
+        goto bail;
+    if (padding != 0) {
+        result = pEntry->addPadding(padding);
+        if (result != NO_ERROR)
+            goto bail;
+    }
+
+    /*
+     * From here on out, failures are more interesting.
+     */
+    mNeedCDRewrite = true;
+
+    /*
+     * Write the LFH.  Since we're not recompressing the data, we already
+     * have all of the fields filled out.
+     */
+    lfhPosn = ftell(mZipFp);
+    pEntry->mLFH.write(mZipFp);
+
+    /*
+     * Copy the data over.
+     *
+     * If the "has data descriptor" flag is set, we want to copy the DD
+     * fields as well.  This is a fixed-size area immediately following
+     * the data.
+     */
+    if (fseek(pSourceZip->mZipFp, pSourceEntry->getFileOffset(), SEEK_SET) != 0)
+    {
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    off_t copyLen;
+    copyLen = pSourceEntry->getCompressedLen();
+    if ((pSourceEntry->mLFH.mGPBitFlag & ZipEntry::kUsesDataDescr) != 0)
+        copyLen += ZipEntry::kDataDescriptorLen;
+
+    if (copyPartialFpToFp(mZipFp, pSourceZip->mZipFp, copyLen, NULL)
+        != NO_ERROR)
+    {
+        LOGW("copy of '%s' failed\n", pEntry->mCDE.mFileName);
+        result = UNKNOWN_ERROR;
+        goto bail;
+    }
+
+    /*
+     * Update file offsets.
+     */
+    endPosn = ftell(mZipFp);
+
+    /*
+     * Success!  Fill out new values.
+     */
+    pEntry->setLFHOffset(lfhPosn);      // sets mCDE.mLocalHeaderRelOffset
+    mEOCD.mNumEntries++;
+    mEOCD.mTotalNumEntries++;
+    mEOCD.mCentralDirSize = 0;      // mark invalid; set by flush()
+    mEOCD.mCentralDirOffset = endPosn;
+
+    /*
+     * Add pEntry to the list.
+     */
+    mEntries.add(pEntry);
+    if (ppEntry != NULL)
+        *ppEntry = pEntry;
+    pEntry = NULL;
+
+    result = NO_ERROR;
+
+bail:
+    delete pEntry;
+    return result;
+}
+
+/*
+ * Copy all of the bytes in "src" to "dst".
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the data.
+ */
+status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
+{
+    unsigned char tmpBuf[32768];
+    size_t count;
+
+    *pCRC32 = crc32(0L, Z_NULL, 0);
+
+    while (1) {
+        count = fread(tmpBuf, 1, sizeof(tmpBuf), srcFp);
+        if (ferror(srcFp) || ferror(dstFp))
+            return errnoToStatus(errno);
+        if (count == 0)
+            break;
+
+        *pCRC32 = crc32(*pCRC32, tmpBuf, count);
+
+        if (fwrite(tmpBuf, 1, count, dstFp) != count) {
+            LOGD("fwrite %d bytes failed\n", (int) count);
+            return UNKNOWN_ERROR;
+        }
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Copy all of the bytes in "src" to "dst".
+ *
+ * On exit, "dstFp" will be seeked immediately past the data.
+ */
+status_t ZipFile::copyDataToFp(FILE* dstFp,
+    const void* data, size_t size, unsigned long* pCRC32)
+{
+    size_t count;
+
+    *pCRC32 = crc32(0L, Z_NULL, 0);
+    if (size > 0) {
+        *pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);
+        if (fwrite(data, 1, size, dstFp) != size) {
+            LOGD("fwrite %d bytes failed\n", (int) size);
+            return UNKNOWN_ERROR;
+        }
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Copy some of the bytes in "src" to "dst".
+ *
+ * If "pCRC32" is NULL, the CRC will not be computed.
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the data just written.
+ */
+status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
+    unsigned long* pCRC32)
+{
+    unsigned char tmpBuf[32768];
+    size_t count;
+
+    if (pCRC32 != NULL)
+        *pCRC32 = crc32(0L, Z_NULL, 0);
+
+    while (length) {
+        long readSize;
+        
+        readSize = sizeof(tmpBuf);
+        if (readSize > length)
+            readSize = length;
+
+        count = fread(tmpBuf, 1, readSize, srcFp);
+        if ((long) count != readSize) {     // error or unexpected EOF
+            LOGD("fread %d bytes failed\n", (int) readSize);
+            return UNKNOWN_ERROR;
+        }
+
+        if (pCRC32 != NULL)
+            *pCRC32 = crc32(*pCRC32, tmpBuf, count);
+
+        if (fwrite(tmpBuf, 1, count, dstFp) != count) {
+            LOGD("fwrite %d bytes failed\n", (int) count);
+            return UNKNOWN_ERROR;
+        }
+
+        length -= readSize;
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Compress all of the data in "srcFp" and write it to "dstFp".
+ *
+ * On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
+ * will be seeked immediately past the compressed data.
+ */
+status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
+    const void* data, size_t size, unsigned long* pCRC32)
+{
+    status_t result = NO_ERROR;
+    const size_t kBufSize = 32768;
+    unsigned char* inBuf = NULL;
+    unsigned char* outBuf = NULL;
+    z_stream zstream;
+    bool atEof = false;     // no feof() aviailable yet
+    unsigned long crc;
+    int zerr;
+
+    /*
+     * Create an input buffer and an output buffer.
+     */
+    inBuf = new unsigned char[kBufSize];
+    outBuf = new unsigned char[kBufSize];
+    if (inBuf == NULL || outBuf == NULL) {
+        result = NO_MEMORY;
+        goto bail;
+    }
+
+    /*
+     * Initialize the zlib stream.
+     */
+    memset(&zstream, 0, sizeof(zstream));
+    zstream.zalloc = Z_NULL;
+    zstream.zfree = Z_NULL;
+    zstream.opaque = Z_NULL;
+    zstream.next_in = NULL;
+    zstream.avail_in = 0;
+    zstream.next_out = outBuf;
+    zstream.avail_out = kBufSize;
+    zstream.data_type = Z_UNKNOWN;
+
+    zerr = deflateInit2(&zstream, Z_BEST_COMPRESSION,
+        Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
+    if (zerr != Z_OK) {
+        result = UNKNOWN_ERROR;
+        if (zerr == Z_VERSION_ERROR) {
+            LOGE("Installed zlib is not compatible with linked version (%s)\n",
+                ZLIB_VERSION);
+        } else {
+            LOGD("Call to deflateInit2 failed (zerr=%d)\n", zerr);
+        }
+        goto bail;
+    }
+
+    crc = crc32(0L, Z_NULL, 0);
+
+    /*
+     * Loop while we have data.
+     */
+    do {
+        size_t getSize;
+        int flush;
+
+        /* only read if the input buffer is empty */
+        if (zstream.avail_in == 0 && !atEof) {
+            LOGV("+++ reading %d bytes\n", (int)kBufSize);
+            if (data) {
+                getSize = size > kBufSize ? kBufSize : size;
+                memcpy(inBuf, data, getSize);
+                data = ((const char*)data) + getSize;
+                size -= getSize;
+            } else {
+                getSize = fread(inBuf, 1, kBufSize, srcFp);
+                if (ferror(srcFp)) {
+                    LOGD("deflate read failed (errno=%d)\n", errno);
+                    goto z_bail;
+                }
+            }
+            if (getSize < kBufSize) {
+                LOGV("+++  got %d bytes, EOF reached\n",
+                    (int)getSize);
+                atEof = true;
+            }
+
+            crc = crc32(crc, inBuf, getSize);
+
+            zstream.next_in = inBuf;
+            zstream.avail_in = getSize;
+        }
+
+        if (atEof)
+            flush = Z_FINISH;       /* tell zlib that we're done */
+        else
+            flush = Z_NO_FLUSH;     /* more to come! */
+
+        zerr = deflate(&zstream, flush);
+        if (zerr != Z_OK && zerr != Z_STREAM_END) {
+            LOGD("zlib deflate call failed (zerr=%d)\n", zerr);
+            result = UNKNOWN_ERROR;
+            goto z_bail;
+        }
+
+        /* write when we're full or when we're done */
+        if (zstream.avail_out == 0 ||
+            (zerr == Z_STREAM_END && zstream.avail_out != (uInt) kBufSize))
+        {
+            LOGV("+++ writing %d bytes\n", (int) (zstream.next_out - outBuf));
+            if (fwrite(outBuf, 1, zstream.next_out - outBuf, dstFp) !=
+                (size_t)(zstream.next_out - outBuf))
+            {
+                LOGD("write %d failed in deflate\n",
+                    (int) (zstream.next_out - outBuf));
+                goto z_bail;
+            }
+
+            zstream.next_out = outBuf;
+            zstream.avail_out = kBufSize;
+        }
+    } while (zerr == Z_OK);
+
+    assert(zerr == Z_STREAM_END);       /* other errors should've been caught */
+
+    *pCRC32 = crc;
+
+z_bail:
+    deflateEnd(&zstream);        /* free up any allocated structures */
+
+bail:
+    delete[] inBuf;
+    delete[] outBuf;
+
+    return result;
+}
+
+/*
+ * Mark an entry as deleted.
+ *
+ * We will eventually need to crunch the file down, but if several files
+ * are being removed (perhaps as part of an "update" process) we can make
+ * things considerably faster by deferring the removal to "flush" time.
+ */
+status_t ZipFile::remove(ZipEntry* pEntry)
+{
+    /*
+     * Should verify that pEntry is actually part of this archive, and
+     * not some stray ZipEntry from a different file.
+     */
+
+    /* mark entry as deleted, and mark archive as dirty */
+    pEntry->setDeleted();
+    mNeedCDRewrite = true;
+    return NO_ERROR;
+}
+
+/*
+ * Flush any pending writes.
+ *
+ * In particular, this will crunch out deleted entries, and write the
+ * Central Directory and EOCD if we have stomped on them.
+ */
+status_t ZipFile::flush(void)
+{
+    status_t result = NO_ERROR;
+    long eocdPosn;
+    int i, count;
+
+    if (mReadOnly)
+        return INVALID_OPERATION;
+    if (!mNeedCDRewrite)
+        return NO_ERROR;
+
+    assert(mZipFp != NULL);
+
+    result = crunchArchive();
+    if (result != NO_ERROR)
+        return result;
+
+    if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0)
+        return UNKNOWN_ERROR;
+
+    count = mEntries.size();
+    for (i = 0; i < count; i++) {
+        ZipEntry* pEntry = mEntries[i];
+        pEntry->mCDE.write(mZipFp);
+    }
+
+    eocdPosn = ftell(mZipFp);
+    mEOCD.mCentralDirSize = eocdPosn - mEOCD.mCentralDirOffset;
+
+    mEOCD.write(mZipFp);
+
+    /*
+     * If we had some stuff bloat up during compression and get replaced
+     * with plain files, or if we deleted some entries, there's a lot
+     * of wasted space at the end of the file.  Remove it now.
+     */
+    if (ftruncate(fileno(mZipFp), ftell(mZipFp)) != 0) {
+        LOGW("ftruncate failed %ld: %s\n", ftell(mZipFp), strerror(errno));
+        // not fatal
+    }
+
+    /* should we clear the "newly added" flag in all entries now? */
+
+    mNeedCDRewrite = false;
+    return NO_ERROR;
+}
+
+/*
+ * Crunch deleted files out of an archive by shifting the later files down.
+ *
+ * Because we're not using a temp file, we do the operation inside the
+ * current file.
+ */
+status_t ZipFile::crunchArchive(void)
+{
+    status_t result = NO_ERROR;
+    int i, count;
+    long delCount, adjust;
+
+#if 0
+    printf("CONTENTS:\n");
+    for (i = 0; i < (int) mEntries.size(); i++) {
+        printf(" %d: lfhOff=%ld del=%d\n",
+            i, mEntries[i]->getLFHOffset(), mEntries[i]->getDeleted());
+    }
+    printf("  END is %ld\n", (long) mEOCD.mCentralDirOffset);
+#endif
+
+    /*
+     * Roll through the set of files, shifting them as appropriate.  We
+     * could probably get a slight performance improvement by sliding
+     * multiple files down at once (because we could use larger reads
+     * when operating on batches of small files), but it's not that useful.
+     */
+    count = mEntries.size();
+    delCount = adjust = 0;
+    for (i = 0; i < count; i++) {
+        ZipEntry* pEntry = mEntries[i];
+        long span;
+
+        if (pEntry->getLFHOffset() != 0) {
+            long nextOffset;
+
+            /* Get the length of this entry by finding the offset
+             * of the next entry.  Directory entries don't have
+             * file offsets, so we need to find the next non-directory
+             * entry.
+             */
+            nextOffset = 0;
+            for (int ii = i+1; nextOffset == 0 && ii < count; ii++)
+                nextOffset = mEntries[ii]->getLFHOffset();
+            if (nextOffset == 0)
+                nextOffset = mEOCD.mCentralDirOffset;
+            span = nextOffset - pEntry->getLFHOffset();
+
+            assert(span >= ZipEntry::LocalFileHeader::kLFHLen);
+        } else {
+            /* This is a directory entry.  It doesn't have
+             * any actual file contents, so there's no need to
+             * move anything.
+             */
+            span = 0;
+        }
+
+        //printf("+++ %d: off=%ld span=%ld del=%d [count=%d]\n",
+        //    i, pEntry->getLFHOffset(), span, pEntry->getDeleted(), count);
+
+        if (pEntry->getDeleted()) {
+            adjust += span;
+            delCount++;
+
+            delete pEntry;
+            mEntries.removeAt(i);
+
+            /* adjust loop control */
+            count--;
+            i--;
+        } else if (span != 0 && adjust > 0) {
+            /* shuffle this entry back */
+            //printf("+++ Shuffling '%s' back %ld\n",
+            //    pEntry->getFileName(), adjust);
+            result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
+                        pEntry->getLFHOffset(), span);
+            if (result != NO_ERROR) {
+                /* this is why you use a temp file */
+                LOGE("error during crunch - archive is toast\n");
+                return result;
+            }
+
+            pEntry->setLFHOffset(pEntry->getLFHOffset() - adjust);
+        }
+    }
+
+    /*
+     * Fix EOCD info.  We have to wait until the end to do some of this
+     * because we use mCentralDirOffset to determine "span" for the
+     * last entry.
+     */
+    mEOCD.mCentralDirOffset -= adjust;
+    mEOCD.mNumEntries -= delCount;
+    mEOCD.mTotalNumEntries -= delCount;
+    mEOCD.mCentralDirSize = 0;  // mark invalid; set by flush()
+
+    assert(mEOCD.mNumEntries == mEOCD.mTotalNumEntries);
+    assert(mEOCD.mNumEntries == count);
+
+    return result;
+}
+
+/*
+ * Works like memmove(), but on pieces of a file.
+ */
+status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
+{
+    if (dst == src || n <= 0)
+        return NO_ERROR;
+
+    unsigned char readBuf[32768];
+
+    if (dst < src) {
+        /* shift stuff toward start of file; must read from start */
+        while (n != 0) {
+            size_t getSize = sizeof(readBuf);
+            if (getSize > n)
+                getSize = n;
+
+            if (fseek(fp, (long) src, SEEK_SET) != 0) {
+                LOGD("filemove src seek %ld failed\n", (long) src);
+                return UNKNOWN_ERROR;
+            }
+
+            if (fread(readBuf, 1, getSize, fp) != getSize) {
+                LOGD("filemove read %ld off=%ld failed\n",
+                    (long) getSize, (long) src);
+                return UNKNOWN_ERROR;
+            }
+
+            if (fseek(fp, (long) dst, SEEK_SET) != 0) {
+                LOGD("filemove dst seek %ld failed\n", (long) dst);
+                return UNKNOWN_ERROR;
+            }
+
+            if (fwrite(readBuf, 1, getSize, fp) != getSize) {
+                LOGD("filemove write %ld off=%ld failed\n",
+                    (long) getSize, (long) dst);
+                return UNKNOWN_ERROR;
+            }
+
+            src += getSize;
+            dst += getSize;
+            n -= getSize;
+        }
+    } else {
+        /* shift stuff toward end of file; must read from end */
+        assert(false);      // write this someday, maybe
+        return UNKNOWN_ERROR;
+    }
+
+    return NO_ERROR;
+}
+
+
+/*
+ * Get the modification time from a file descriptor.
+ */
+time_t ZipFile::getModTime(int fd)
+{
+    struct stat sb;
+
+    if (fstat(fd, &sb) < 0) {
+        LOGD("HEY: fstat on fd %d failed\n", fd);
+        return (time_t) -1;
+    }
+
+    return sb.st_mtime;
+}
+
+
+#if 0       /* this is a bad idea */
+/*
+ * Get a copy of the Zip file descriptor.
+ *
+ * We don't allow this if the file was opened read-write because we tend
+ * to leave the file contents in an uncertain state between calls to
+ * flush().  The duplicated file descriptor should only be valid for reads.
+ */
+int ZipFile::getZipFd(void) const
+{
+    if (!mReadOnly)
+        return INVALID_OPERATION;
+    assert(mZipFp != NULL);
+
+    int fd;
+    fd = dup(fileno(mZipFp));
+    if (fd < 0) {
+        LOGD("didn't work, errno=%d\n", errno);
+    }
+
+    return fd;
+}
+#endif
+
+
+#if 0
+/*
+ * Expand data.
+ */
+bool ZipFile::uncompress(const ZipEntry* pEntry, void* buf) const
+{
+    return false;
+}
+#endif
+
+// free the memory when you're done
+void* ZipFile::uncompress(const ZipEntry* entry)
+{
+    size_t unlen = entry->getUncompressedLen();
+    size_t clen = entry->getCompressedLen();
+
+    void* buf = malloc(unlen);
+    if (buf == NULL) {
+        return NULL;
+    }
+
+    fseek(mZipFp, 0, SEEK_SET);
+
+    off_t offset = entry->getFileOffset();
+    if (fseek(mZipFp, offset, SEEK_SET) != 0) {
+        goto bail;
+    }
+
+    switch (entry->getCompressionMethod())
+    {
+        case ZipEntry::kCompressStored: {
+            ssize_t amt = fread(buf, 1, unlen, mZipFp);
+            if (amt != (ssize_t)unlen) {
+                goto bail;
+            }
+#if 0
+            printf("data...\n");
+            const unsigned char* p = (unsigned char*)buf;
+            const unsigned char* end = p+unlen;
+            for (int i=0; i<32 && p < end; i++) {
+                printf("0x%08x ", (int)(offset+(i*0x10)));
+                for (int j=0; j<0x10 && p < end; j++) {
+                    printf(" %02x", *p);
+                    p++;
+                }
+                printf("\n");
+            }
+#endif
+
+            }
+            break;
+        case ZipEntry::kCompressDeflated: {
+            if (!ZipUtils::inflateToBuffer(mZipFp, buf, unlen, clen)) {
+                goto bail;
+            }
+            }
+            break;
+        default:
+            goto bail;
+    }
+    return buf;
+
+bail:
+    free(buf);
+    return NULL;
+}
+
+
+/*
+ * ===========================================================================
+ *      ZipFile::EndOfCentralDir
+ * ===========================================================================
+ */
+
+/*
+ * Read the end-of-central-dir fields.
+ *
+ * "buf" should be positioned at the EOCD signature, and should contain
+ * the entire EOCD area including the comment.
+ */
+status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
+{
+    /* don't allow re-use */
+    assert(mComment == NULL);
+
+    if (len < kEOCDLen) {
+        /* looks like ZIP file got truncated */
+        LOGD(" Zip EOCD: expected >= %d bytes, found %d\n",
+            kEOCDLen, len);
+        return INVALID_OPERATION;
+    }
+
+    /* this should probably be an assert() */
+    if (ZipEntry::getLongLE(&buf[0x00]) != kSignature)
+        return UNKNOWN_ERROR;
+
+    mDiskNumber = ZipEntry::getShortLE(&buf[0x04]);
+    mDiskWithCentralDir = ZipEntry::getShortLE(&buf[0x06]);
+    mNumEntries = ZipEntry::getShortLE(&buf[0x08]);
+    mTotalNumEntries = ZipEntry::getShortLE(&buf[0x0a]);
+    mCentralDirSize = ZipEntry::getLongLE(&buf[0x0c]);
+    mCentralDirOffset = ZipEntry::getLongLE(&buf[0x10]);
+    mCommentLen = ZipEntry::getShortLE(&buf[0x14]);
+
+    // TODO: validate mCentralDirOffset
+
+    if (mCommentLen > 0) {
+        if (kEOCDLen + mCommentLen > len) {
+            LOGD("EOCD(%d) + comment(%d) exceeds len (%d)\n",
+                kEOCDLen, mCommentLen, len);
+            return UNKNOWN_ERROR;
+        }
+        mComment = new unsigned char[mCommentLen];
+        memcpy(mComment, buf + kEOCDLen, mCommentLen);
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Write an end-of-central-directory section.
+ */
+status_t ZipFile::EndOfCentralDir::write(FILE* fp)
+{
+    unsigned char buf[kEOCDLen];
+
+    ZipEntry::putLongLE(&buf[0x00], kSignature);
+    ZipEntry::putShortLE(&buf[0x04], mDiskNumber);
+    ZipEntry::putShortLE(&buf[0x06], mDiskWithCentralDir);
+    ZipEntry::putShortLE(&buf[0x08], mNumEntries);
+    ZipEntry::putShortLE(&buf[0x0a], mTotalNumEntries);
+    ZipEntry::putLongLE(&buf[0x0c], mCentralDirSize);
+    ZipEntry::putLongLE(&buf[0x10], mCentralDirOffset);
+    ZipEntry::putShortLE(&buf[0x14], mCommentLen);
+
+    if (fwrite(buf, 1, kEOCDLen, fp) != kEOCDLen)
+        return UNKNOWN_ERROR;
+    if (mCommentLen > 0) {
+        assert(mComment != NULL);
+        if (fwrite(mComment, mCommentLen, 1, fp) != mCommentLen)
+            return UNKNOWN_ERROR;
+    }
+
+    return NO_ERROR;
+}
+
+/*
+ * Dump the contents of an EndOfCentralDir object.
+ */
+void ZipFile::EndOfCentralDir::dump(void) const
+{
+    LOGD(" EndOfCentralDir contents:\n");
+    LOGD("  diskNum=%u diskWCD=%u numEnt=%u totalNumEnt=%u\n",
+        mDiskNumber, mDiskWithCentralDir, mNumEntries, mTotalNumEntries);
+    LOGD("  centDirSize=%lu centDirOff=%lu commentLen=%u\n",
+        mCentralDirSize, mCentralDirOffset, mCommentLen);
+}
+
diff --git a/tools/zipalign/ZipFile.h b/tools/zipalign/ZipFile.h
new file mode 100644
index 0000000..dbbd072
--- /dev/null
+++ b/tools/zipalign/ZipFile.h
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// General-purpose Zip archive access.  This class allows both reading and
+// writing to Zip archives, including deletion of existing entries.
+//
+#ifndef __LIBS_ZIPFILE_H
+#define __LIBS_ZIPFILE_H
+
+#include <utils/Vector.h>
+#include <utils/Errors.h>
+#include <stdio.h>
+
+#include "ZipEntry.h"
+
+namespace android {
+
+/*
+ * Manipulate a Zip archive.
+ *
+ * Some changes will not be visible in the until until "flush" is called.
+ *
+ * The correct way to update a file archive is to make all changes to a
+ * copy of the archive in a temporary file, and then unlink/rename over
+ * the original after everything completes.  Because we're only interested
+ * in using this for packaging, we don't worry about such things.  Crashing
+ * after making changes and before flush() completes could leave us with
+ * an unusable Zip archive.
+ */
+class ZipFile {
+public:
+    ZipFile(void)
+      : mZipFp(NULL), mReadOnly(false), mNeedCDRewrite(false)
+      {}
+    ~ZipFile(void) {
+        if (!mReadOnly)
+            flush();
+        if (mZipFp != NULL)
+            fclose(mZipFp);
+        discardEntries();
+    }
+
+    /*
+     * Open a new or existing archive.
+     */
+    typedef enum {
+        kOpenReadOnly   = 0x01,
+        kOpenReadWrite  = 0x02,
+        kOpenCreate     = 0x04,     // create if it doesn't exist
+        kOpenTruncate   = 0x08,     // if it exists, empty it
+    };
+    status_t open(const char* zipFileName, int flags);
+
+    /*
+     * Add a file to the end of the archive.  Specify whether you want the
+     * library to try to store it compressed.
+     *
+     * If "storageName" is specified, the archive will use that instead
+     * of "fileName".
+     *
+     * If there is already an entry with the same name, the call fails.
+     * Existing entries with the same name must be removed first.
+     *
+     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+     */
+    status_t add(const char* fileName, int compressionMethod,
+        ZipEntry** ppEntry)
+    {
+        return add(fileName, fileName, compressionMethod, ppEntry);
+    }
+    status_t add(const char* fileName, const char* storageName,
+        int compressionMethod, ZipEntry** ppEntry)
+    {
+        return addCommon(fileName, NULL, 0, storageName,
+                         ZipEntry::kCompressStored,
+                         compressionMethod, ppEntry);
+    }
+
+    /*
+     * Add a file that is already compressed with gzip.
+     *
+     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+     */
+    status_t addGzip(const char* fileName, const char* storageName,
+        ZipEntry** ppEntry)
+    {
+        return addCommon(fileName, NULL, 0, storageName,
+                         ZipEntry::kCompressDeflated,
+                         ZipEntry::kCompressDeflated, ppEntry);
+    }
+
+    /*
+     * Add a file from an in-memory data buffer.
+     *
+     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+     */
+    status_t add(const void* data, size_t size, const char* storageName,
+        int compressionMethod, ZipEntry** ppEntry)
+    {
+        return addCommon(NULL, data, size, storageName,
+                         ZipEntry::kCompressStored,
+                         compressionMethod, ppEntry);
+    }
+
+    /*
+     * Add an entry by copying it from another zip file.  If "padding" is
+     * nonzero, the specified number of bytes will be added to the "extra"
+     * field in the header.
+     *
+     * If "ppEntry" is non-NULL, a pointer to the new entry will be returned.
+     */
+    status_t add(const ZipFile* pSourceZip, const ZipEntry* pSourceEntry,
+        int padding, ZipEntry** ppEntry);
+
+    /*
+     * Mark an entry as having been removed.  It is not actually deleted
+     * from the archive or our internal data structures until flush() is
+     * called.
+     */
+    status_t remove(ZipEntry* pEntry);
+
+    /*
+     * Flush changes.  If mNeedCDRewrite is set, this writes the central dir.
+     */
+    status_t flush(void);
+
+    /*
+     * Expand the data into the buffer provided.  The buffer must hold
+     * at least <uncompressed len> bytes.  Variation expands directly
+     * to a file.
+     *
+     * Returns "false" if an error was encountered in the compressed data.
+     */
+    //bool uncompress(const ZipEntry* pEntry, void* buf) const;
+    //bool uncompress(const ZipEntry* pEntry, FILE* fp) const;
+    void* uncompress(const ZipEntry* pEntry);
+
+    /*
+     * Get an entry, by name.  Returns NULL if not found.
+     *
+     * Does not return entries pending deletion.
+     */
+    ZipEntry* getEntryByName(const char* fileName) const;
+
+    /*
+     * Get the Nth entry in the archive.
+     *
+     * This will return an entry that is pending deletion.
+     */
+    int getNumEntries(void) const { return mEntries.size(); }
+    ZipEntry* getEntryByIndex(int idx) const;
+
+private:
+    /* these are private and not defined */
+    ZipFile(const ZipFile& src);
+    ZipFile& operator=(const ZipFile& src);
+
+    class EndOfCentralDir {
+    public:
+        EndOfCentralDir(void) :
+            mDiskNumber(0),
+            mDiskWithCentralDir(0),
+            mNumEntries(0),
+            mTotalNumEntries(0),
+            mCentralDirSize(0),
+            mCentralDirOffset(0),
+            mCommentLen(0),
+            mComment(NULL)
+            {}
+        virtual ~EndOfCentralDir(void) {
+            delete[] mComment;
+        }
+
+        status_t readBuf(const unsigned char* buf, int len);
+        status_t write(FILE* fp);
+
+        //unsigned long   mSignature;
+        unsigned short  mDiskNumber;
+        unsigned short  mDiskWithCentralDir;
+        unsigned short  mNumEntries;
+        unsigned short  mTotalNumEntries;
+        unsigned long   mCentralDirSize;
+        unsigned long   mCentralDirOffset;      // offset from first disk
+        unsigned short  mCommentLen;
+        unsigned char*  mComment;
+
+        enum {
+            kSignature      = 0x06054b50,
+            kEOCDLen        = 22,       // EndOfCentralDir len, excl. comment
+
+            kMaxCommentLen  = 65535,    // longest possible in ushort
+            kMaxEOCDSearch  = kMaxCommentLen + EndOfCentralDir::kEOCDLen,
+
+        };
+
+        void dump(void) const;
+    };
+
+
+    /* read all entries in the central dir */
+    status_t readCentralDir(void);
+
+    /* crunch deleted entries out */
+    status_t crunchArchive(void);
+
+    /* clean up mEntries */
+    void discardEntries(void);
+
+    /* common handler for all "add" functions */
+    status_t addCommon(const char* fileName, const void* data, size_t size,
+        const char* storageName, int sourceType, int compressionMethod,
+        ZipEntry** ppEntry);
+
+    /* copy all of "srcFp" into "dstFp" */
+    status_t copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32);
+    /* copy all of "data" into "dstFp" */
+    status_t copyDataToFp(FILE* dstFp,
+        const void* data, size_t size, unsigned long* pCRC32);
+    /* copy some of "srcFp" into "dstFp" */
+    status_t copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
+        unsigned long* pCRC32);
+    /* like memmove(), but on parts of a single file */
+    status_t filemove(FILE* fp, off_t dest, off_t src, size_t n);
+    /* compress all of "srcFp" into "dstFp", using Deflate */
+    status_t compressFpToFp(FILE* dstFp, FILE* srcFp,
+        const void* data, size_t size, unsigned long* pCRC32);
+
+    /* get modification date from a file descriptor */
+    time_t getModTime(int fd);
+
+    /*
+     * We use stdio FILE*, which gives us buffering but makes dealing
+     * with files >2GB awkward.  Until we support Zip64, we're fine.
+     */
+    FILE*           mZipFp;             // Zip file pointer
+
+    /* one of these per file */
+    EndOfCentralDir mEOCD;
+
+    /* did we open this read-only? */
+    bool            mReadOnly;
+
+    /* set this when we trash the central dir */
+    bool            mNeedCDRewrite;
+
+    /*
+     * One ZipEntry per entry in the zip file.  I'm using pointers instead
+     * of objects because it's easier than making operator= work for the
+     * classes and sub-classes.
+     */
+    Vector<ZipEntry*>   mEntries;
+};
+
+}; // namespace android
+
+#endif // __LIBS_ZIPFILE_H