move sensors dump to gs-common

Bug: 250475720
Test: adb bugreport
Change-Id: I15ec38810792c9216ad63de59a8f3aeb5f871bc5
diff --git a/sensors/Android.bp b/sensors/Android.bp
new file mode 100644
index 0000000..dec4991
--- /dev/null
+++ b/sensors/Android.bp
@@ -0,0 +1,20 @@
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+    name: "dump_sensors",
+    srcs: ["dump_sensors.cpp"],
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+    shared_libs: [
+    	"libbase",
+	"libdumpstateutil",
+	"libdump",
+    ],
+    vendor: true,
+    relative_install_path: "dump",
+}
diff --git a/sensors/dump_sensors.cpp b/sensors/dump_sensors.cpp
new file mode 100644
index 0000000..58d63e9
--- /dev/null
+++ b/sensors/dump_sensors.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2022 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.
+ */
+#include <stdio.h>
+#include <string>
+#include <android-base/properties.h>
+#include <dump/pixel_dump.h>
+#include "DumpstateUtil.h"
+
+int main() {
+    setbuf(stdout, NULL);
+
+    runCommand("USF statistics", "/vendor/bin/usf_stats get --all");
+    if (!::android::os::dumpstate::PropertiesHelper::IsUserBuild()) {
+        // Not a user build, if this is also not a production device dump the USF registry.
+        std::string hwRev = ::android::base::GetProperty("ro.boot.hardware.revision", "");
+        if (hwRev.find("PROTO") != std::string::npos ||
+            hwRev.find("EVT") != std::string::npos ||
+            hwRev.find("DVT") != std::string::npos ||
+            hwRev.find("PVT") != std::string::npos) {
+            runCommand("USF Registry", "/vendor/bin/usf_reg_edit save -");
+            dumpFileContent("USF Last Stat Buffer", "/data/vendor/sensors/debug/stats.history");
+        }
+    }
+    return 0;
+}
diff --git a/sensors/sensors.mk b/sensors/sensors.mk
new file mode 100644
index 0000000..143a379
--- /dev/null
+++ b/sensors/sensors.mk
@@ -0,0 +1,3 @@
+$(call inherit-product-if-exists, vendor/google/sensors/usf/android/usf_efw_product.mk)
+BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/sensors/sepolicy
+
diff --git a/sensors/sepolicy/dump_sensors.te b/sensors/sepolicy/dump_sensors.te
new file mode 100644
index 0000000..7d37a63
--- /dev/null
+++ b/sensors/sepolicy/dump_sensors.te
@@ -0,0 +1,11 @@
+pixel_bugreport(dump_sensors)
+allow dump_sensors aoc_device:chr_file rw_file_perms;
+allow dump_sensors device:dir r_dir_perms;
+allow dump_sensors vendor_shell_exec:file execute_no_trans;
+allow dump_sensors vendor_usf_stats:file execute_no_trans;
+
+userdebug_or_eng(`
+  allow dump_sensors vendor_usf_reg_edit:file execute_no_trans;
+  allow dump_sensors sensor_debug_data_file:dir r_dir_perms;
+  allow dump_sensors sensor_debug_data_file:file r_file_perms;
+')
diff --git a/sensors/sepolicy/file.te b/sensors/sepolicy/file.te
new file mode 100644
index 0000000..97084b6
--- /dev/null
+++ b/sensors/sepolicy/file.te
@@ -0,0 +1,2 @@
+type vendor_usf_stats, vendor_file_type, file_type;
+type vendor_usf_reg_edit, vendor_file_type, file_type;
diff --git a/sensors/sepolicy/file_contexts b/sensors/sepolicy/file_contexts
new file mode 100644
index 0000000..0fbbdf2
--- /dev/null
+++ b/sensors/sepolicy/file_contexts
@@ -0,0 +1,3 @@
+/vendor/bin/dump/dump_sensors      u:object_r:dump_sensors_exec:s0
+/vendor/bin/usf_stats              u:object_r:vendor_usf_stats:s0
+/vendor/bin/usf_reg_edit           u:object_r:vendor_usf_reg_edit:s0