Snap for 7550930 from 069316a93cb305bf016310fa1bcbe6a34e83804c to mainline-resolv-release

Change-Id: Iff53698d4e08d424a6eaea88de67786284f07a34
diff --git a/Android.bp b/Android.bp
index 9f68463..ee6dc4f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -12,6 +12,17 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+package {
+    default_applicable_licenses: ["external_bsdiff_license"],
+}
+
+license {
+    name: "external_bsdiff_license",
+    visibility: [":__subpackages__"],
+    license_kinds: ["SPDX-license-identifier-Apache-2.0","SPDX-license-identifier-BSD"],
+    license_text: ["LICENSE"],
+}
+
 cc_defaults {
     name: "bsdiff_defaults",
     host_supported: true,
@@ -40,6 +51,7 @@
         "//bootable/recovery:__subpackages__",
         "//external/puffin:__subpackages__",
         "//system/update_engine:__subpackages__",
+        "//system/core/fs_mgr/libsnapshot:__subpackages__",
     ],
 
     srcs: [
@@ -151,4 +163,7 @@
             cflags: ["-DBSDIFF_TARGET_UNITTEST"],
         },
     },
+    test_options: {
+        unit_test: true,
+    },
 }
diff --git a/AndroidTest.xml b/AndroidTest.xml
deleted file mode 100644
index 6394c0e..0000000
--- a/AndroidTest.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2017 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<configuration description="Config for bsdiff_unittest">
-    <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
-        <option name="cleanup" value="true" />
-        <option name="push" value="bsdiff_unittest->/data/local/tmp/bsdiff_unittest" />
-    </target_preparer>
-    <option name="test-suite-tag" value="apct" />
-    <test class="com.android.tradefed.testtype.GTest" >
-        <option name="native-test-device-path" value="/data/local/tmp" />
-        <option name="module-name" value="bsdiff_unittest" />
-    </test>
-</configuration>
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..d97975c
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,3 @@
+third_party {
+  license_type: NOTICE
+}
diff --git a/NOTICE b/NOTICE
deleted file mode 120000
index 7a694c9..0000000
--- a/NOTICE
+++ /dev/null
@@ -1 +0,0 @@
-LICENSE
\ No newline at end of file
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..598f4c9
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,7 @@
+{
+  "presubmit": [
+    {
+      "name": "bsdiff_unittest"
+    }
+  ]
+}
diff --git a/extents_file_unittest.cc b/extents_file_unittest.cc
index 7dc23be..38f288a 100644
--- a/extents_file_unittest.cc
+++ b/extents_file_unittest.cc
@@ -178,8 +178,9 @@
   // A second read that fails will succeed if there was partial data read.
   EXPECT_CALL(*mock_file_, Read(_, 10, _)).WillOnce(Return(false));
 
+  char* buf = reinterpret_cast<char*>(0x1234);
   size_t bytes_read = 0;
-  EXPECT_TRUE(file.Read(nullptr, 100, &bytes_read));
+  EXPECT_TRUE(file.Read(buf, 100, &bytes_read));
   EXPECT_EQ(1U, bytes_read);
 }
 
diff --git a/test_utils.cc b/test_utils.cc
index eb079d5..c1350eb 100644
--- a/test_utils.cc
+++ b/test_utils.cc
@@ -53,11 +53,8 @@
 
 void BsdiffTestEnvironment::SetUp() {
 #ifdef BSDIFF_TARGET_UNITTEST
-#define BSDIFF_TARGET_TMP_BASE "/data/tmp"
-      if (access(BSDIFF_TARGET_TMP_BASE, F_OK) == -1) {
-        mkdir(BSDIFF_TARGET_TMP_BASE, S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH);
-      }
-      setenv("TMPDIR", BSDIFF_TARGET_TMP_BASE, 1);
+#define BSDIFF_TARGET_TMP_BASE "/data/local/tmp"
+  setenv("TMPDIR", BSDIFF_TARGET_TMP_BASE, 1);
 #endif  // defined (BSDIFF_TARGET_UNITTEST)
 }
 
diff --git a/utils.cc b/utils.cc
index c3e613e..c82eb98 100644
--- a/utils.cc
+++ b/utils.cc
@@ -7,6 +7,11 @@
 namespace bsdiff {
 
 int64_t ParseInt64(const uint8_t* buf) {
+  // BSPatch uses a non-standard encoding of integers.
+  // Highest bit of that integer is used as a sign bit, 1 = negative
+  // and 0 = positive.
+  // Therefore, if the highest bit is set, flip it, then do 2's complement
+  // to get the integer in standard form
   int64_t result = buf[7] & 0x7F;
   for (int i = 6; i >= 0; i--) {
     result <<= 8;