Merge "vndk-def: Update template makefile"
diff --git a/scripts/native_heapdump_viewer.py b/scripts/native_heapdump_viewer.py
index 0689a1d..5d5db10 100755
--- a/scripts/native_heapdump_viewer.py
+++ b/scripts/native_heapdump_viewer.py
@@ -86,9 +86,10 @@
 re_map = re.compile("(?P<start>[0-9a-f]+)-(?P<end>[0-9a-f]+) .... (?P<offset>[0-9a-f]+) [0-9a-f]+:[0-9a-f]+ [0-9]+ +(?P<name>.*)")
 
 class Backtrace:
-    def __init__(self, is_zygote, size, frames):
+    def __init__(self, is_zygote, size, num_allocs, frames):
         self.is_zygote = is_zygote
         self.size = size
+        self.num_allocs = num_allocs
         self.frames = frames
 
 class Mapping:
@@ -105,18 +106,43 @@
         self.library = library
 
 
+def GetVersion(native_heap):
+  """Get the version of the native heap dump."""
+
+  re_line = re.compile("Android\s+Native\s+Heap\s+Dump\s+(?P<version>v\d+\.\d+)\s*$")
+  matched = 0
+  for line in open(native_heap, "r"):
+    m = re_line.match(line)
+    if m:
+      return m.group('version')
+  return None
+
+version = GetVersion(native_heap)
+if not version or version == "v1.0":
+  # Version v1.0 was produced by a buggy version of malloc debug where the
+  # num field was set incorrectly.
+  num_field_valid = False
+else:
+  num_field_valid = True
+
 backtraces = []
 mappings = []
 
 for line in open(native_heap, "r"):
+    # Format of line:
+    #   z 0  sz       50  num    1  bt 000000000000a100 000000000000b200
     parts = line.split()
     if len(parts) > 7 and parts[0] == "z" and parts[2] == "sz":
         is_zygote = parts[1] != "1"
         size = int(parts[3])
+        if num_field_valid:
+          num_allocs = int(parts[5])
+        else:
+          num_allocs = 1
         frames = map(lambda x: int(x, 16), parts[7:])
         if reverse_frames:
             frames = list(reversed(frames))
-        backtraces.append(Backtrace(is_zygote, size, frames))
+        backtraces.append(Backtrace(is_zygote, size, num_allocs, frames))
         continue
 
     m = re_map.match(line)
@@ -209,16 +235,17 @@
         self.addr = addr
         self.size = 0
         self.number = 0
+        self.num_allocs = 0
         self.children = {}
 
-    def addStack(self, size, stack):
-        self.size += size
-        self.number += 1
+    def addStack(self, size, num_allocs, stack):
+        self.size += size * num_allocs
+        self.number += num_allocs
         if len(stack) > 0:
             child = stack[0]
             if not (child.addr in self.children):
                 self.children[child.addr] = child
-            self.children[child.addr].addStack(size, stack[1:])
+            self.children[child.addr].addStack(size, num_allocs, stack[1:])
 
 zygote = AddrInfo("ZYGOTE")
 app = AddrInfo("APP")
@@ -272,9 +299,9 @@
         stack.append(AddrInfo("%x" % addr))
     stack.reverse()
     if backtrace.is_zygote:
-        zygote.addStack(backtrace.size, stack)
+        zygote.addStack(backtrace.size, backtrace.num_allocs, stack)
     else:
-        app.addStack(backtrace.size, stack)
+        app.addStack(backtrace.size, backtrace.num_allocs, stack)
 
 html_header = """
 <!DOCTYPE html>
diff --git a/vndk/OWNERS b/vndk/OWNERS
index e80d02c..402c928 100644
--- a/vndk/OWNERS
+++ b/vndk/OWNERS
@@ -1,2 +1,2 @@
-loganchien@google.com
 andrewhsieh@google.com
+loganchien@google.com
diff --git a/vndk/snapshot/OWNERS b/vndk/snapshot/OWNERS
new file mode 100644
index 0000000..c567ff6
--- /dev/null
+++ b/vndk/snapshot/OWNERS
@@ -0,0 +1,2 @@
+andrewhsieh@google.com
+jaeshin@google.com
diff --git a/vndk/tools/OWNERS b/vndk/tools/OWNERS
new file mode 100644
index 0000000..e5641ae
--- /dev/null
+++ b/vndk/tools/OWNERS
@@ -0,0 +1,4 @@
+andrewhsieh@google.com
+loganchien@google.com
+per-file build_mixed = jaeshin@google.com
+per-file build_mixed = schwartzmi@google.com
diff --git a/vndk/tools/build_mixed b/vndk/tools/build_mixed
index 2a6cbcf..1c15d53 100755
--- a/vndk/tools/build_mixed
+++ b/vndk/tools/build_mixed
@@ -2,8 +2,16 @@
 usage () {
     echo "Create a Mixed Build archive with the given GSI and device archives."
     echo
-    echo "Usage: $0 gsi_build_dir device_build_dir out_dir [check_tool]"
+    echo "Usage: $0 [-v <vendor_version>] [-m <modify_system_image_path>] "
+    echo "    gsi_build_dir device_build_dir out_dir [check_tool]"
     echo
+    echo "Options -v and -m must precede positional arguments."
+    echo
+    echo "vendor_version is the version of the vendor image when the mixed"
+    echo "    build is inter branch. Optional."
+    echo "    eg. 8.1.0 for a mixed build of GSI and O-MR1 vendor image."
+    echo "modify_system_image_path is the path to the script that modifies the"
+    echo "    system image for an inter branch build target. Optional."
     echo "gsi_build_dir is the path to the GSI build"
     echo "    eg. aosp_arm64_ab-userdebug."
     echo "device_build_dir is the path to the device build"
@@ -13,12 +21,6 @@
     echo "    used to verify the compatibility of the given images. Optional."
 }
 
-readonly GSI_DIR="$1"
-readonly DEVICE_DIR="$2"
-readonly DIST_DIR="$3"
-readonly CHECK_TOOL="$4"
-readonly TEMP_DIR=$(mktemp -d "/tmp/$(basename $0)_XXXXXXXX")
-
 # Print error message and exit.
 # Usage: exit_badparam message
 #
@@ -37,6 +39,43 @@
 
 trap cleanup_and_exit EXIT
 
+while getopts :v:m: opt; do
+    case "$opt" in
+        v)
+            readonly VENDOR_VERSION="$OPTARG"
+            ;;
+        m)
+            readonly MODIFY_SYSTEM_SCRIPT="$OPTARG"
+            ;;
+        \?)
+            exit_badparam "Invalid options: -"$OPTARG""
+            ;;
+        :)
+            exit_badparam "Option -"$OPTARG" requires an argument."
+            ;;
+    esac
+done
+
+if [[ "$OPTIND" -gt 1 && "$OPTIND" -lt 5 ]]; then
+    exit_badparam "Options -v and -m must be set together."
+fi
+
+shift "$((OPTIND-1))"
+
+if [[ ! -z "${MODIFY_SYSTEM_SCRIPT+x}" && ! -f "$MODIFY_SYSTEM_SCRIPT" ]]; then
+    exit_badparam "Script not found: "$MODIFY_SYSTEM_SCRIPT""
+fi
+
+if [[ $# -lt 3 ]]; then
+    exit_badparam "Unexpected number of arguments"
+fi
+
+readonly GSI_DIR="$1"
+readonly DEVICE_DIR="$2"
+readonly DIST_DIR="$3"
+readonly CHECK_TOOL="$4"
+readonly TEMP_DIR="$(mktemp -d /tmp/"$(basename $0)"_XXXXXXXX)"
+
 readonly GSI_TARGET_FILES_ARCHIVE="$(find "$GSI_DIR" -name "*-target_files-*.zip" -print)"
 if [[ ! -f "$GSI_TARGET_FILES_ARCHIVE" ]]; then
     exit_badparam "Could not find GSI target_files archive in $GSI_DIR."
@@ -44,16 +83,12 @@
 
 readonly DEVICE_ARCHIVE="$(find "$DEVICE_DIR" -name "*-img-*.zip" -print)"
 if [[ ! -f "$DEVICE_ARCHIVE" ]]; then
-    exit_badparam "Could not find GSI img archive in $DEVICE_DIR."
+    exit_badparam "Could not find device img archive in $DEVICE_DIR."
 fi
 
 readonly DEVICE_TARGET_FILES_ARCHIVE="$(find "$DEVICE_DIR" -name "*-target_files-*.zip" -print)"
 if [[ ! -f "$DEVICE_ARCHIVE" ]]; then
-    exit_badparam "Could not find GSI target_files archive in $DEVICE_DIR."
-fi
-
-if [[ $# -lt 3 ]]; then
-    exit_badparam "Unexpected number of arguments"
+    exit_badparam "Could not find device target_files archive in $DEVICE_DIR."
 fi
 
 readonly DEVICE_ARTIFACTS_DIR="$TEMP_DIR"/device_archive_artifacts
@@ -61,12 +96,15 @@
 readonly GSI_ARTIFACTS_DIR="$TEMP_DIR"/gsi_artifacts
 readonly GSI_IMAGES_DIR="$GSI_ARTIFACTS_DIR"/IMAGES
 
+readonly SPL_PROPERTY_NAME="ro.build.version.security_patch"
+readonly SYSTEM_BUILD_PROP="SYSTEM/build.prop"
+
 ###
 # Uncompress the archives.
 mkdir -p "$GSI_ARTIFACTS_DIR"
 # Get the GSI images and meta data.
 unzip "$GSI_TARGET_FILES_ARCHIVE" \
-  IMAGES/system.img IMAGES/vbmeta.img META/system_matrix.xml META/system_manifest.xml \
+  IMAGES/system.img IMAGES/vbmeta.img META/system_matrix.xml META/system_manifest.xml "$SYSTEM_BUILD_PROP" \
   -d "$GSI_ARTIFACTS_DIR"
 
 mkdir -p "$DEVICE_IMAGES_DIR"
@@ -74,7 +112,7 @@
 unzip "$DEVICE_ARCHIVE" -d "$DEVICE_IMAGES_DIR"
 # Get the device meta data.
 unzip "$DEVICE_TARGET_FILES_ARCHIVE" \
-  META/vendor_matrix.xml META/vendor_manifest.xml \
+  META/vendor_matrix.xml META/vendor_manifest.xml "$SYSTEM_BUILD_PROP" \
   -d "$DEVICE_ARTIFACTS_DIR"
 
 ###
@@ -89,6 +127,31 @@
 fi
 
 ###
+# Modify system.img if vendor version is provided.
+if [[ ! -z "${VENDOR_VERSION+x}" ]]; then
+    # Create copy of GSI target files package that can be modified
+    # since the original $GSI_TARGET_FILES_ARCHIVE is a symlink to
+    # prebuilt files in cache
+    cp "$GSI_TARGET_FILES_ARCHIVE" "$TEMP_DIR"
+    readonly COPY_GSI_TARGET_FILES_ARCHIVE="$TEMP_DIR"/"$(basename "$GSI_TARGET_FILES_ARCHIVE")"
+
+    # Check compatibility of security patch level
+    readonly SYSTEM_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$GSI_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP")
+    readonly VENDOR_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$DEVICE_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP")
+    declare -a args
+    args=(-v "$VENDOR_VERSION" "$COPY_GSI_TARGET_FILES_ARCHIVE")
+    if [[ "$SYSTEM_SPL" != "$VENDOR_SPL" ]]; then
+        echo "Security patch level mismatch detected..."
+        echo "  SPL of system: "$SYSTEM_SPL""
+        echo "  SPL of vendor: "$VENDOR_SPL""
+        args+=("$VENDOR_SPL")
+    fi
+    "$MODIFY_SYSTEM_SCRIPT" "${args[@]}"
+    # Replace system.img with newly modified system.img
+    unzip -o "$COPY_GSI_TARGET_FILES_ARCHIVE" IMAGES/system.img -d "$GSI_ARTIFACTS_DIR"
+fi
+
+###
 # Overwrite artifacts in the device archive to create the Mixed Build artifacts.
 cp "$GSI_IMAGES_DIR"/system.img "$DEVICE_IMAGES_DIR"/
 
@@ -111,7 +174,8 @@
     mkdir -p "$DIST_DIR" || true
 fi
 # Archive all the device artifacts.
-rsync -av --exclude='logs' "$DEVICE_DIR"/* "$DIST_DIR"
+rsync --archive --verbose --copy-links --exclude='logs' \
+  "$DEVICE_DIR"/* "$DIST_DIR"
 # Overwrite the image archive with the Mixed Build archive.
 OUT_ARCHIVE="$DIST_DIR"/"$(basename $DEVICE_ARCHIVE)"
 cp "$DEVICE_IMAGES_DIR"/mixed.zip "$OUT_ARCHIVE"
diff --git a/vndk/tools/definition-tool/OWNERS b/vndk/tools/definition-tool/OWNERS
new file mode 100644
index 0000000..402c928
--- /dev/null
+++ b/vndk/tools/definition-tool/OWNERS
@@ -0,0 +1,2 @@
+andrewhsieh@google.com
+loganchien@google.com
diff --git a/vndk/tools/header-checker/OWNERS b/vndk/tools/header-checker/OWNERS
new file mode 100644
index 0000000..9104083
--- /dev/null
+++ b/vndk/tools/header-checker/OWNERS
@@ -0,0 +1,2 @@
+andrewhsieh@google.com
+jchowdhary@google.com
diff --git a/vndk/tools/header-checker/header-abi-diff/src/header_abi_diff.cpp b/vndk/tools/header-checker/header-abi-diff/src/header_abi_diff.cpp
index 369b73a..f576470 100644
--- a/vndk/tools/header-checker/header-abi-diff/src/header_abi_diff.cpp
+++ b/vndk/tools/header-checker/header-abi-diff/src/header_abi_diff.cpp
@@ -126,6 +126,16 @@
 static const char kWarn[] = "\033[36;1mwarning: \033[0m";
 static const char kError[] = "\033[31;1merror: \033[0m";
 
+bool ShouldEmitWarningMessage(abi_util::CompatibilityStatusIR status) {
+  return (!allow_extensions &&
+      (status & abi_util::CompatibilityStatusIR::Extension)) ||
+      (!allow_unreferenced_changes &&
+      (status & abi_util::CompatibilityStatusIR::UnreferencedChanges)) ||
+      (!allow_unreferenced_elf_symbol_changes &&
+      (status & abi_util::CompatibilityStatusIR::ElfIncompatible)) ||
+      (status & abi_util::CompatibilityStatusIR::Incompatible);
+}
+
 int main(int argc, const char **argv) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "header-checker");
   std::set<std::string> ignored_symbols;
@@ -168,15 +178,10 @@
     unreferenced_change_str += " This MIGHT be an ABI breaking change due to";
     unreferenced_change_str += " internal typecasts.";
   }
-  bool suppress_extending_warnings =
-      allow_extensions && (status & abi_util::CompatibilityStatusIR::Extension);
 
-  bool suppress_elf_warnings =
-      allow_unreferenced_elf_symbol_changes &&
-      (status & abi_util::CompatibilityStatusIR::ElfIncompatible);
+  bool should_emit_warning_message = ShouldEmitWarningMessage(status);
 
-  if (!suppress_local_warnings && !suppress_extending_warnings &&
-      !suppress_elf_warnings && status) {
+  if (should_emit_warning_message) {
     llvm::errs() << "******************************************************\n"
                  << error_or_warning_str
                  << "VNDK library: "
@@ -189,13 +194,7 @@
                  << "******************************************************\n";
   }
 
-  if (!advice_only && ((!allow_extensions &&
-      (status & abi_util::CompatibilityStatusIR::Extension)) ||
-      (!allow_unreferenced_changes &&
-      (status & abi_util::CompatibilityStatusIR::UnreferencedChanges)) ||
-      (!allow_unreferenced_elf_symbol_changes &&
-      (status & abi_util::CompatibilityStatusIR::ElfIncompatible)) ||
-      (status & abi_util::CompatibilityStatusIR::Incompatible))) {
+  if (!advice_only && should_emit_warning_message) {
     return status;
   }
 
diff --git a/vndk/tools/header-checker/header-abi-util/src/ir_representation_protobuf.cpp b/vndk/tools/header-checker/header-abi-util/src/ir_representation_protobuf.cpp
index b259de4..972ec39 100644
--- a/vndk/tools/header-checker/header-abi-util/src/ir_representation_protobuf.cpp
+++ b/vndk/tools/header-checker/header-abi-util/src/ir_representation_protobuf.cpp
@@ -1179,11 +1179,6 @@
     return CompatibilityStatusIR::Incompatible;
   }
 
-  if(diff_tu_->removed_elf_functions().size() != 0 ||
-     diff_tu_->removed_elf_objects().size() != 0) {
-    return CompatibilityStatusIR::ElfIncompatible;
-  }
-
   CompatibilityStatusIR combined_status = CompatibilityStatusIR::Compatible;
 
   if (diff_tu_->enum_type_extension_diffs().size() != 0 ||
@@ -1203,6 +1198,11 @@
         combined_status | CompatibilityStatusIR::UnreferencedChanges;
   }
 
+  if(diff_tu_->removed_elf_functions().size() != 0 ||
+     diff_tu_->removed_elf_objects().size() != 0) {
+    combined_status = combined_status | CompatibilityStatusIR::ElfIncompatible;
+  }
+
   return combined_status;
 }
 
diff --git a/vndk/tools/header-checker/tests/integration/cpp/gold/low_volume_speaker.cpp b/vndk/tools/header-checker/tests/integration/cpp/gold/low_volume_speaker.cpp
index 4d1aee5..04d9693 100644
--- a/vndk/tools/header-checker/tests/integration/cpp/gold/low_volume_speaker.cpp
+++ b/vndk/tools/header-checker/tests/integration/cpp/gold/low_volume_speaker.cpp
@@ -2,3 +2,12 @@
 
 void LowVolumeSpeaker::Speak() { }
 LISTEN_RETURN_TYPE LowVolumeSpeaker::Listen() { LISTEN_RETURN_STATEMENT }
+
+#ifdef ADD_UNEXPORTED_ELF_SYMBOL
+void UnexportedSymbol(int *a) {
+  if (a) {
+    a++;
+  }
+  a--;
+}
+#endif
diff --git a/vndk/tools/header-checker/tests/integration/cpp/gold/map_add_function_elf_symbol.txt b/vndk/tools/header-checker/tests/integration/cpp/gold/map_add_function_elf_symbol.txt
new file mode 100644
index 0000000..ca5cd02
--- /dev/null
+++ b/vndk/tools/header-checker/tests/integration/cpp/gold/map_add_function_elf_symbol.txt
@@ -0,0 +1,20 @@
+libcpp_golden_added_function {
+global:
+    _Z26test_virtual_function_callP12SuperSpeaker;
+    _ZN12SuperSpeaker11SpeakLouderEv;
+    _ZN12SuperSpeaker18CreateSuperSpeakerEi;
+    _ZN12SuperSpeaker9SpeakLoudEv;
+    _ZN12SuperSpeakerD2Ev;
+    _ZN16LowVolumeSpeaker5SpeakEv;
+    _ZN16LowVolumeSpeaker6ListenEv;
+    _ZN16LowVolumeSpeakerD0Ev;
+    _ZN17HighVolumeSpeaker11BadPracticeEf;
+    _ZN17HighVolumeSpeaker13AddedFunctionEv;
+    _ZN17HighVolumeSpeaker5SpeakEv;
+    _ZN17HighVolumeSpeaker6ListenEv;
+    _ZN17HighVolumeSpeakerD0Ev;
+    _ZN12NotReferenced;
+    _ZN16UnexportedSymbol;
+    _ZTV16LowVolumeSpeaker; #var
+    _ZTV17HighVolumeSpeaker; #var
+};
diff --git a/vndk/tools/header-checker/tests/module.py b/vndk/tools/header-checker/tests/module.py
index 3277698..0df8b2a 100755
--- a/vndk/tools/header-checker/tests/module.py
+++ b/vndk/tools/header-checker/tests/module.py
@@ -184,6 +184,19 @@
         api = 'current',
     ),
     Module(
+        name = 'libgolden_cpp_add_function_and_unexported_elf',
+        srcs = ['integration/cpp/gold/golden_1.cpp',
+                'integration/cpp/gold/high_volume_speaker.cpp',
+                'integration/cpp/gold/low_volume_speaker.cpp',
+                ],
+        version_script = \
+            'integration/cpp/gold/map_add_function_elf_symbol.txt',
+        export_include_dirs = ['integration/cpp/gold/include'],
+        cflags = ['-DGOLDEN_ADD_FUNCTION=1', '-DADD_UNEXPORTED_ELF_SYMBOL'],
+        arch = '',
+        api = 'current',
+    ),
+    Module(
         name = 'libgolden_cpp_change_function_access',
         srcs = ['integration/cpp/gold/golden_1.cpp',
                 'integration/cpp/gold/high_volume_speaker.cpp',
diff --git a/vndk/tools/header-checker/tests/test.py b/vndk/tools/header-checker/tests/test.py
index f6d9c91..ed186ad 100755
--- a/vndk/tools/header-checker/tests/test.py
+++ b/vndk/tools/header-checker/tests/test.py
@@ -159,6 +159,16 @@
         self.prepare_and_run_abi_diff_all_archs(
             "libgolden_cpp", "libgolden_cpp_add_function", 4)
 
+    def test_libgolden_cpp_add_function_allow_extension(self):
+        self.prepare_and_run_abi_diff_all_archs(
+            "libgolden_cpp", "libgolden_cpp_add_function", 0,
+            ['-allow-extensions'])
+
+    def test_libgolden_cpp_add_function_and_elf_symbol(self):
+        self.prepare_and_run_abi_diff_all_archs(
+            "libgolden_cpp", "libgolden_cpp_add_function_and_unexported_elf",
+            4)
+
     def test_libgolden_cpp_change_function_access(self):
         self.prepare_and_run_abi_diff_all_archs(
             "libgolden_cpp", "libgolden_cpp_change_function_access", 8)
diff --git a/vndk/tools/modify_system_img.sh b/vndk/tools/modify_system_img.sh
new file mode 100755
index 0000000..9c21aab
--- /dev/null
+++ b/vndk/tools/modify_system_img.sh
@@ -0,0 +1,174 @@
+#!/bin/bash -ex
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+usage () {
+    echo "Modifies the system image in a target_files.zip package so that it is"
+    echo "    compatible with vendor images of older Android versions."
+    echo "    This script is intended to be run on the Android build servers"
+    echo "    for inter branch mixed build targets."
+    echo
+    echo "Usage: $0 [-v <vendor_version>]"
+    echo "    <target_files_path> [<new_security_patch_level>]"
+    echo
+    echo "vendor_version is the version of the vendor image"
+    echo "    e.g. 8.1.0 for Android version O-MR1"
+    echo "new_security_patch_level is the value to replace the SPL in the"
+    echo "    original system.img"
+    echo "target_files_path is the path to the *-target_files-*.zip file"
+}
+
+# Print error message and exit.
+# Usage: exit_badparam message
+#
+# message is a string to be displayed before exit.
+exit_badparam () {
+    echo "ERROR: $1" >&2
+    usage
+    exit 1
+}
+
+cleanup_and_exit () {
+    readonly result="$?"
+    rm -rf "$TEMP_DIR"
+    exit "$result"
+}
+
+trap cleanup_and_exit EXIT
+
+while getopts :v: opt; do
+    case "$opt" in
+        v)
+            readonly VENDOR_VERSION="$OPTARG"
+            ;;
+        \?)
+            exit_badparam "Invalid options: -"$OPTARG""
+            ;;
+        :)
+            exit_badparam "Option -"$OPTARG" requires an argument."
+            ;;
+    esac
+done
+shift "$((OPTIND-1))"
+
+if [[ $# -lt 1 || $# -gt 2 ]]; then
+    exit_badparam "Unexpected number of arguments"
+fi
+
+readonly SYSTEM_TARGET_FILES="$1"
+readonly NEW_SPL="$2"
+
+if [[ ! -f "$SYSTEM_TARGET_FILES" ]]; then
+    exit_badparam "Could not find system target files package, "$SYSTEM_TARGET_FILES""
+fi
+
+# SPL must have YYYY-MM-DD format
+if [[ $# -eq 2 ]] && [[ ! "$NEW_SPL" =~ ^[0-9]{4}-(0[0-9]|1[012])-([012][0-9]|3[01])$ ]]; then
+    exit_badparam "<new_security_patch_level> must have YYYY-MM-DD format"
+fi
+
+if [[ -z "${ANDROID_BUILD_TOP+x}" ]]; then
+    build_top=""
+else
+    build_top="$ANDROID_BUILD_TOP"/
+fi
+
+readonly add_img_to_target_files="$build_top"build/make/tools/releasetools/add_img_to_target_files.py
+
+# Check required script
+if [[ ! -f "$add_img_to_target_files" ]]; then
+    echo "Error: Cannot find script,", "$add_img_to_target_files"
+    echo "Please run lunch or run from root of source tree."
+    exit 1
+fi
+
+readonly TEMP_DIR="$(mktemp -d /tmp/"$(basename $0)"_XXXXXXXX)"
+readonly SPL_PROPERTY_NAME="ro.build.version.security_patch"
+readonly RELEASE_VERSION_PROPERTY_NAME="ro.build.version.release"
+readonly VNDK_VERSION_PROPERTY="ro.vndk.version"
+readonly VNDK_VERSION_PROPERTY_OMR1="$VNDK_VERSION_PROPERTY"=27
+
+readonly BUILD_PROP_PATH="SYSTEM/build.prop"
+readonly PROP_DEFAULT_PATH="SYSTEM/etc/prop.default"
+
+# Unzip build.prop and prop.default from target_files.zip
+unzip "$SYSTEM_TARGET_FILES" "$BUILD_PROP_PATH" "$PROP_DEFAULT_PATH" -d "$TEMP_DIR"
+
+readonly BUILD_PROP_FILE="$TEMP_DIR"/"$BUILD_PROP_PATH"
+readonly PROP_DEFAULT_FILE="$TEMP_DIR"/"$PROP_DEFAULT_PATH"
+
+if [[ -f "$BUILD_PROP_FILE" ]]; then
+    readonly CURRENT_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$BUILD_PROP_FILE")
+    readonly CURRENT_VERSION=$(sed -n -r "s/^"$RELEASE_VERSION_PROPERTY_NAME"=(.*)$/\1/p" "$BUILD_PROP_FILE")
+    echo "Reading build.prop..."
+    echo "  Current security patch level: "$CURRENT_SPL""
+    echo "  Current release version: "$CURRENT_VERSION""
+
+    # Update SPL to <new_security_patch_level>
+    if [[ "$NEW_SPL" != "" ]]; then
+        if [[ "$CURRENT_SPL" == "" ]]; then
+            echo "ERROR: Cannot find "$SPL_PROPERTY_NAME" in "$BUILD_PROP_PATH""
+            exit 1
+        else
+            # Replace the property inplace
+            sed -i "s/^"$SPL_PROPERTY_NAME"=.*$/"$SPL_PROPERTY_NAME"="$NEW_SPL"/" "$BUILD_PROP_FILE"
+            echo "Replacing..."
+            echo "  New security patch level: "$NEW_SPL""
+        fi
+    fi
+
+    # Update release version to <vendor_version>
+    if [[ "$VENDOR_VERSION" != "" ]]; then
+        if [[ "$CURRENT_VERSION" == "" ]]; then
+            echo "ERROR: Cannot find "$RELEASE_VERSION_PROPERTY_NAME" in "$BUILD_PROP_PATH""
+            exit 1
+        else
+            # Replace the property inplace
+            sed -i "s/^"$RELEASE_VERSION_PROPERTY_NAME"=.*$/"$RELEASE_VERSION_PROPERTY_NAME"="$VENDOR_VERSION"/" "$BUILD_PROP_FILE"
+            echo "Replacing..."
+            echo "  New release version for vendor.img: "$VENDOR_VERSION""
+        fi
+
+        if [[ "$VENDOR_VERSION" == "8.1.0" ]]; then
+            # add ro.vndk.version for O-MR1
+            if [[ -f "$PROP_DEFAULT_FILE" ]]; then
+                readonly CURRENT_VNDK_VERSION=$(sed -n -r "s/^"$VNDK_VERSION_PROPERTY"=(.*)$/\1/p" "$PROP_DEFAULT_FILE")
+                if [[ "$CURRENT_VNDK_VERSION" != "" ]]; then
+                    echo "WARNING: "$VNDK_VERSION_PROPERTY" is already set to "$CURRENT_VNDK_VERSION" in "$PROP_DEFAULT_PATH""
+                    echo "DID NOT overwrite "$VNDK_VERSION_PROPERTY""
+                else
+                    echo "Adding \""$VNDK_VERSION_PROPERTY_OMR1"\" to "$PROP_DEFAULT_PATH" for O-MR1 vendor image."
+                    sed -i -e "\$a\#\n\# FOR O-MR1 DEVICES\n\#\n"$VNDK_VERSION_PROPERTY_OMR1"" "$PROP_DEFAULT_FILE"
+                fi
+            else
+                echo "ERROR: Cannot find "$PROP_DEFAULT_PATH" in "$SYSTEM_TARGET_FILES""
+            fi
+        fi
+    fi
+else
+    echo "ERROR: Cannot find "$BUILD_PROP_PATH" in "$SYSTEM_TARGET_FILES""
+    exit 1
+fi
+
+# Re-zip build.prop and prop.default
+(
+    cd "$TEMP_DIR"
+    zip -ur "$SYSTEM_TARGET_FILES" ./*
+)
+
+# Rebuild system.img
+zip -d "$SYSTEM_TARGET_FILES" IMAGES/system\*
+"$add_img_to_target_files" -a "$SYSTEM_TARGET_FILES"
+
+echo "Done."
diff --git a/vndk/tools/sourcedr/OWNERS b/vndk/tools/sourcedr/OWNERS
new file mode 100644
index 0000000..402c928
--- /dev/null
+++ b/vndk/tools/sourcedr/OWNERS
@@ -0,0 +1,2 @@
+andrewhsieh@google.com
+loganchien@google.com
diff --git a/vndk/tools/vtable-dumper/OWNERS b/vndk/tools/vtable-dumper/OWNERS
new file mode 100644
index 0000000..9104083
--- /dev/null
+++ b/vndk/tools/vtable-dumper/OWNERS
@@ -0,0 +1,2 @@
+andrewhsieh@google.com
+jchowdhary@google.com