auto import from //branches/cupcake/...@127101
diff --git a/tools/applypatch/Android.mk b/tools/applypatch/Android.mk
index 725c21f..09f9862 100644
--- a/tools/applypatch/Android.mk
+++ b/tools/applypatch/Android.mk
@@ -17,12 +17,12 @@
 
 ifneq ($(TARGET_SIMULATOR),true)
 
-LOCAL_SRC_FILES := applypatch.c xdelta3.c bsdiff.c freecache.c
+LOCAL_SRC_FILES := applypatch.c bsdiff.c freecache.c
 LOCAL_MODULE := applypatch
 LOCAL_FORCE_STATIC_EXECUTABLE := true
 LOCAL_MODULE_TAGS := eng
-LOCAL_C_INCLUDES += external/xdelta3 external/bzip2
-LOCAL_STATIC_LIBRARIES += libxdelta3 libmincrypt libbz libc
+LOCAL_C_INCLUDES += external/bzip2
+LOCAL_STATIC_LIBRARIES += libmincrypt libbz libc
 
 include $(BUILD_EXECUTABLE)
 
diff --git a/tools/applypatch/applypatch.c b/tools/applypatch/applypatch.c
index 23ed715..9954869 100644
--- a/tools/applypatch/applypatch.c
+++ b/tools/applypatch/applypatch.c
@@ -1,20 +1,17 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #include <errno.h>
@@ -209,24 +206,6 @@
 }
 
 int ShowLicenses() {
-  puts("\nCopyright (C) 2008 The Android Open Source Project\n"
-       "\n"
-       "This program is free software; you can redistribute it and/or\n"
-       "modify it under the terms of the GNU General Public License\n"
-       "as published by the Free Software Foundation; either version 2\n"
-       "of the License, or (at your option) any later version.\n"
-       "\n"
-       "This program is distributed in the hope that it will be useful,\n"
-       "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-       "GNU General Public License for more details.\n"
-       "\n"
-       "You should have received a copy of the GNU General Public License\n"
-       "along with this program; if not, write to the Free Software\n"
-       "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n"
-       "02110-1301, USA.\n"
-       "\n------------------\n"
-       );
   ShowBSDiffLicense();
   return 0;
 }
@@ -251,10 +230,10 @@
 //   successfully.
 //
 // - otherwise, if the sha1 hash of <file> is <src-sha1>, applies the
-//   xdelta3 or bsdiff <patch> to <file> to produce a new file (the
-//   type of patch is automatically detected from the file header).
-//   If that new file has sha1 hash <tgt-sha1>, moves it to replace
-//   <file>, and exits successfully.
+//   bsdiff <patch> to <file> to produce a new file (the type of patch
+//   is automatically detected from the file header).  If that new
+//   file has sha1 hash <tgt-sha1>, moves it to replace <file>, and
+//   exits successfully.
 //
 // - otherwise, or if any error is encountered, exits with non-zero
 //   status.
@@ -426,12 +405,8 @@
       header[2] == 0xc4 && header[3] == 0) {
     // xdelta3 patches begin "VCD" (with the high bits set) followed
     // by a zero byte (the version number).
-    int result = ApplyXDelta3Patch(source_to_use->data, source_to_use->size,
-                                   patch_filename, output, &ctx);
-    if (result != 0) {
-      fprintf(stderr, "ApplyXDelta3Patch failed\n");
-      return result;
-    }
+    fprintf(stderr, "error:  xdelta3 patches no longer supported\n");
+    return 1;
   } else if (header_bytes_read >= 8 &&
              memcmp(header, "BSDIFF40", 8) == 0) {
     int result = ApplyBSDiffPatch(source_to_use->data, source_to_use->size,
diff --git a/tools/applypatch/applypatch.h b/tools/applypatch/applypatch.h
index 3059e22..76fc80a 100644
--- a/tools/applypatch/applypatch.h
+++ b/tools/applypatch/applypatch.h
@@ -1,20 +1,17 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #ifndef _APPLYPATCH_H
@@ -44,11 +41,6 @@
 // applypatch.c
 size_t FreeSpaceForFile(const char* filename);
 
-// xdelta3.c
-int ApplyXDelta3Patch(const unsigned char* old_data, ssize_t old_size,
-                      const char* patch_filename,
-                      FILE* output, SHA_CTX* ctx);
-
 // bsdiff.c
 void ShowBSDiffLicense();
 int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
diff --git a/tools/applypatch/applypatch.sh b/tools/applypatch/applypatch.sh
index 193e7fd..181cd5c 100755
--- a/tools/applypatch/applypatch.sh
+++ b/tools/applypatch/applypatch.sh
@@ -128,7 +128,7 @@
 # --------------- apply patch ----------------------
 
 $ADB push $DATA_DIR/old.file $WORK_DIR
-$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
+$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
 
 # Check that the partition has enough space to apply the patch without
 # copying.  If it doesn't, we'll be testing the low-space condition
@@ -145,19 +145,6 @@
   exit 1
 fi
 
-testname "apply xdelta3 patch"
-run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
-$ADB pull $WORK_DIR/old.file $tmpdir/patched
-diff -q $DATA_DIR/new.file $tmpdir/patched || fail
-
-testname "reapply xdelta3 patch"
-run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
-$ADB pull $WORK_DIR/old.file $tmpdir/patched
-diff -q $DATA_DIR/new.file $tmpdir/patched || fail
-
-$ADB push $DATA_DIR/old.file $WORK_DIR
-$ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
-
 testname "apply bsdiff patch"
 run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
 $ADB pull $WORK_DIR/old.file $tmpdir/patched
@@ -172,7 +159,6 @@
 # --------------- apply patch with low space on /system ----------------------
 
 $ADB push $DATA_DIR/old.file $WORK_DIR
-$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
 $ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
 
 free_kb=$(free_space $WORK_FS)
@@ -182,18 +168,6 @@
 free_kb=$(free_space $WORK_FS)
 echo "${free_kb}kb free on /$WORK_FS now."
 
-testname "apply xdelta3 patch with low space"
-run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
-$ADB pull $WORK_DIR/old.file $tmpdir/patched
-diff -q $DATA_DIR/new.file $tmpdir/patched || fail
-
-testname "reapply xdelta3 patch with low space"
-run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
-$ADB pull $WORK_DIR/old.file $tmpdir/patched
-diff -q $DATA_DIR/new.file $tmpdir/patched || fail
-
-$ADB push $DATA_DIR/old.file $WORK_DIR
-
 testname "apply bsdiff patch with low space"
 run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
 $ADB pull $WORK_DIR/old.file $tmpdir/patched
@@ -207,7 +181,6 @@
 # --------------- apply patch with low space on /system and /cache ----------------------
 
 $ADB push $DATA_DIR/old.file $WORK_DIR
-$ADB push $DATA_DIR/patch.xdelta3 $WORK_DIR
 $ADB push $DATA_DIR/patch.bsdiff $WORK_DIR
 
 free_kb=$(free_space $WORK_FS)
@@ -216,7 +189,7 @@
 run_command mkdir /cache/subdir
 run_command 'echo > /cache/subdir/a.file'
 run_command 'echo > /cache/a.file'
-run_command mkdir -p /cache/recovery/otatest
+run_command mkdir /cache/recovery /cache/recovery/otatest
 run_command 'echo > /cache/recovery/otatest/b.file'
 run_command "echo > $CACHE_TEMP_SOURCE"
 free_kb=$(free_space cache)
@@ -268,8 +241,8 @@
 # put some junk in the old file
 run_command dd if=/dev/urandom of=$WORK_DIR/old.file count=100 bs=1024 || fail
 
-testname "apply xdelta3 patch from cache (corrupted source) with low space"
-run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.xdelta3 || fail
+testname "apply bsdiff patch from cache (corrupted source) with low space"
+run_command $WORK_DIR/applypatch $WORK_DIR/old.file $NEW_SHA1 $NEW_SIZE $BAD1_SHA1:$WORK_DIR/foo $OLD_SHA1:$WORK_DIR/patch.bsdiff || fail
 $ADB pull $WORK_DIR/old.file $tmpdir/patched
 diff -q $DATA_DIR/new.file $tmpdir/patched || fail
 
diff --git a/tools/applypatch/bsdiff.c b/tools/applypatch/bsdiff.c
index f502a6b..a2851f9 100644
--- a/tools/applypatch/bsdiff.c
+++ b/tools/applypatch/bsdiff.c
@@ -1,20 +1,17 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *      http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 // This file is a nearly line-for-line copy of bspatch.c from the
diff --git a/tools/applypatch/testdata/patch.xdelta3 b/tools/applypatch/testdata/patch.xdelta3
deleted file mode 100644
index 2af3ede..0000000
--- a/tools/applypatch/testdata/patch.xdelta3
+++ /dev/null
Binary files differ
diff --git a/tools/applypatch/xdelta3.c b/tools/applypatch/xdelta3.c
deleted file mode 100644
index c9a0f73..0000000
--- a/tools/applypatch/xdelta3.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "xdelta3.h"
-#include "mincrypt/sha.h"
-
-int ApplyXDelta3Patch(const unsigned char* old_data, ssize_t old_size,
-                      const char* patch_filename,
-                      FILE* output, SHA_CTX* ctx) {
-#define WINDOW_SIZE 32768
-
-  int ret;
-  xd3_stream stream;
-  xd3_config config;
-
-  xd3_init_config(&config, 0);
-  config.winsize = WINDOW_SIZE;
-  ret = xd3_config_stream(&stream, &config);
-  if (ret != 0) {
-    fprintf(stderr, "xd3_config_stream error: %s\n", xd3_strerror(ret));
-    return 1;
-  }
-
-  // In xdelta3 terms, the "input" is the patch file: it contains a
-  // sequence of instruction codes and data that will be executed to
-  // produce the output file.  The "source" is the original data file;
-  // it is a blob of data to which instructions in the input may refer
-  // (eg, an instruction may say "copy such-and-such range of bytes
-  // from the source to the output").
-
-  // For simplicity, we provide the entire source to xdelta as a
-  // single block.  This means it should never have to ask us to load
-  // blocks of the source file.
-  xd3_source source;
-  source.name = "old name";
-  source.size = old_size;
-  source.ioh = NULL;
-  source.blksize = old_size;
-  source.curblkno = 0;
-  source.curblk = old_data;
-  source.onblk = old_size;
-
-  ret = xd3_set_source(&stream, &source);
-  if (ret != 0) {
-    fprintf(stderr, "xd3_set_source error: %s\n", xd3_strerror(ret));
-    return 1;
-  }
-
-  unsigned char buffer[WINDOW_SIZE];
-  FILE* input = fopen(patch_filename, "rb");
-  if (input == NULL) {
-    fprintf(stderr, "failed to open patch file %s: %d (%s)\n",
-            patch_filename, errno, strerror(errno));
-    return 1;
-  }
-
-  size_t bytes_read;
-
-  do {
-    bytes_read = fread(buffer, 1, WINDOW_SIZE, input);
-    if (feof(input)) {
-      xd3_set_flags(&stream, XD3_FLUSH);
-    }
-    xd3_avail_input(&stream, buffer, bytes_read);
- process:
-    ret = xd3_decode_input(&stream);
-    switch (ret) {
-      case XD3_INPUT:
-        continue;
-      case XD3_OUTPUT:
-        SHA_update(ctx, stream.next_out, stream.avail_out);
-        if (fwrite(stream.next_out, 1, stream.avail_out, output) !=
-            stream.avail_out) {
-          fprintf(stderr, "short write of output file: %d (%s)\n",
-                  errno, strerror(errno));
-          return 1;
-        }
-        xd3_consume_output(&stream);
-        goto process;
-      case XD3_GETSRCBLK:
-        // We provided the entire source file already; it should never
-        // have to ask us for a block.
-        fprintf(stderr, "xd3_decode_input: unexpected GETSRCBLK\n");
-        return 1;
-      case XD3_GOTHEADER:
-      case XD3_WINSTART:
-      case XD3_WINFINISH:
-        // These are informational events we don't care about.
-        goto process;
-      default:
-        fprintf(stderr, "xd3_decode_input: unknown error %s (%s)\n",
-                xd3_strerror(ret), stream.msg);
-        return 1;
-    }
-  } while (!feof(input));
-
-  fclose(input);
-  return 0;
-
-#undef WINDOW_SIZE
-}