Upgrade  to v1.3.12

This project was upgraded with external_updater.
Usage: tools/external_updater/updater.sh update rmi4utils
For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md

Test: TreeHugger
Change-Id: I5241a32d6ab4ab3e4b87aebd83ddf3ba7f5a9022
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..5b95f0c
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,31 @@
+//
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["external_rmi4utils_license"],
+}
+
+// Added automatically by a large-scale-change
+// See: http://go/android-license-faq
+license {
+    name: "external_rmi4utils_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+    ],
+    license_text: [
+        "LICENSE",
+    ],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 9df8fe7..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,2 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(call all-subdir-makefiles)
\ No newline at end of file
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..04756bb
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,17 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update rmi4utils
+# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md
+
+third_party {
+  url {
+    type: GIT
+    value: "https://github.com/aduggan/rmi4utils.git"
+  }
+  version: "v1.3.12"
+  license_type: NOTICE
+  last_upgrade_date {
+    year: 2022
+    month: 12
+    day: 13
+  }
+}
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..7529cb9
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1 @@
+include platform/system/core:/janitors/OWNERS
diff --git a/f54test/Android.bp b/f54test/Android.bp
new file mode 100644
index 0000000..177fc15
--- /dev/null
+++ b/f54test/Android.bp
@@ -0,0 +1,26 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "external_rmi4utils_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["external_rmi4utils_license"],
+}
+
+cc_binary {
+    name: "f54test",
+    srcs: [
+        "main.cpp",
+        "f54test.cpp",
+        "testutil.cpp",
+        "display.cpp",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-sometimes-uninitialized",
+        "-Wno-unused-private-field",
+        "-Wno-unused-parameter",
+    ],
+    static_libs: ["rmidevice"],
+}
diff --git a/f54test/Android.mk b/f54test/Android.mk
deleted file mode 100644
index 58aa67b..0000000
--- a/f54test/Android.mk
+++ /dev/null
@@ -1,10 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := f54test
-LOCAL_C_INCLUDES := rmidevice
-LOCAL_SRC_FILES := main.cpp f54test.cpp testutil.cpp display.cpp
-LOCAL_CPPFLAGS := -Wall
-LOCAL_STATIC_LIBRARIES := rmidevice
-
-include $(BUILD_EXECUTABLE)
\ No newline at end of file
diff --git a/rmi4update/Android.bp b/rmi4update/Android.bp
new file mode 100644
index 0000000..72a4437
--- /dev/null
+++ b/rmi4update/Android.bp
@@ -0,0 +1,26 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "external_rmi4utils_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["external_rmi4utils_license"],
+}
+
+cc_binary {
+    name: "rmi4update",
+    srcs: [
+        "main.cpp",
+        "rmi4update.cpp",
+        "updateutil.cpp",
+        "firmware_image.cpp",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-private-field",
+        "-Wno-unused-variable",
+    ],
+    static_libs: ["rmidevice"],
+}
diff --git a/rmi4update/Android.mk b/rmi4update/Android.mk
deleted file mode 100644
index 04d0ea8..0000000
--- a/rmi4update/Android.mk
+++ /dev/null
@@ -1,10 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := rmi4update
-LOCAL_C_INCLUDES := rmidevice
-LOCAL_SRC_FILES := main.cpp rmi4update.cpp updateutil.cpp firmware_image.cpp
-LOCAL_CPPFLAGS := -Wall
-LOCAL_STATIC_LIBRARIES := rmidevice
-
-include $(BUILD_EXECUTABLE)
\ No newline at end of file
diff --git a/rmi4update/firmware_image.cpp b/rmi4update/firmware_image.cpp
index ecc2af4..dbc4822 100755
--- a/rmi4update/firmware_image.cpp
+++ b/rmi4update/firmware_image.cpp
@@ -194,6 +194,12 @@
 	m_io = m_memBlock[RMI_IMG_IO_OFFSET];
 	m_bootloaderVersion = m_memBlock[RMI_IMG_BOOTLOADER_VERSION_OFFSET];
 	m_firmwareSize = extract_long(&m_memBlock[RMI_IMG_IMAGE_SIZE_OFFSET]);
+
+	if ((unsigned long)m_imageSize - RMI_IMG_FW_OFFSET - 1 < m_firmwareSize) {
+		fprintf(stderr, "Supplied firmware image size too large, goes out of image file size bound\n");
+		return UPDATE_FAIL_VERIFY_FIRMWARE_SIZE;
+	}
+
 	m_configSize = extract_long(&m_memBlock[RMI_IMG_CONFIG_SIZE_OFFSET]);
 	if (m_io == 1) {
 		m_firmwareBuildID = extract_long(&m_memBlock[RMI_IMG_FW_BUILD_ID_OFFSET]);
diff --git a/rmidevice/Android.bp b/rmidevice/Android.bp
new file mode 100644
index 0000000..9b6ec71
--- /dev/null
+++ b/rmidevice/Android.bp
@@ -0,0 +1,25 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "external_rmi4utils_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["external_rmi4utils_license"],
+}
+
+cc_library_static {
+    name: "rmidevice",
+    srcs: [
+        "hiddevice.cpp",
+        "rmidevice.cpp",
+        "rmifunction.cpp",
+        "util.cpp",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wno-unused-variable",
+    ],
+    export_include_dirs: ["."],
+}
diff --git a/rmidevice/Android.mk b/rmidevice/Android.mk
deleted file mode 100644
index 4f49535..0000000
--- a/rmidevice/Android.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := rmidevice
-LOCAL_SRC_FILES := rmifunction.cpp rmidevice.cpp hiddevice.cpp util.cpp
-LOCAL_CPPFLAGS := -Wall
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/rmihidtool/Android.bp b/rmihidtool/Android.bp
new file mode 100644
index 0000000..0490b2a
--- /dev/null
+++ b/rmihidtool/Android.bp
@@ -0,0 +1,19 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "external_rmi4utils_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["external_rmi4utils_license"],
+}
+
+cc_binary {
+    name: "rmihidtool",
+    srcs: ["main.cpp"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+    static_libs: ["rmidevice"],
+}
diff --git a/rmihidtool/Android.mk b/rmihidtool/Android.mk
deleted file mode 100644
index 6a0c965..0000000
--- a/rmihidtool/Android.mk
+++ /dev/null
@@ -1,10 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := rmihidtool
-LOCAL_C_INCLUDES := rmidevice
-LOCAL_SRC_FILES := main.cpp
-LOCAL_CPPFLAGS := -Wall
-LOCAL_STATIC_LIBRARIES := rmidevice
-
-include $(BUILD_EXECUTABLE)
\ No newline at end of file