Merge "Enable Mapper V5 and Allocator V2" into main
diff --git a/FSTAB_OWNERS b/FSTAB_OWNERS
new file mode 100644
index 0000000..18093a0
--- /dev/null
+++ b/FSTAB_OWNERS
@@ -0,0 +1,11 @@
+# NOTE: CHANGE THIS FILE WITH CAUTIOUS
+# - this file is referenced by other OWNERS file, e.g. device/google/*/OWNERS
+# - changing this file might break the function, check go/gerrit-code-owners-syntax first
+
+jaegeuk@google.com
+huangrandall@google.com
+bvanassche@google.com
+daehojeong@google.com
+chullee@google.com
+vkon@google.com
+thomasyen@google.com
diff --git a/OWNERS b/OWNERS
index b715f13..57ca40f 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,5 +1,5 @@
 
 per-file *.te,*_contexts,te_macros,global_macros=set noparent
 per-file *.te,*_contexts,te_macros,global_macros=file:/sepolicy/OWNERS
-per-file *.mk=set noparent
-per-file *.mk=file:MK_OWNERS
+per-file *.mk,{**/,}Android.bp=set noparent
+per-file *.mk,{**/,}Android.bp=file:MK_OWNERS
diff --git a/camera/lyric.mk b/camera/lyric.mk
index 30e06d1..c886138 100644
--- a/camera/lyric.mk
+++ b/camera/lyric.mk
@@ -14,8 +14,13 @@
 $(call soong_config_set,gch,hwl_library,lyric)
 endif
 
-# Check if we're in the internal build
-ifneq ($(wildcard vendor/google/camera),)
+# Use build-time flag to select whether to build from source
+# or ingest prebuilt-apex.  We would want the development teams
+# using release configuration: (trunk-staging) to build from source.
+# All shipping releases will switch to prebuilts (trunk+)
+# if this condition is not true, then build from source.
+
+ifneq ($(RELEASE_PIXEL_CAMERA_ENABLE_PREBUILT),true)
 
 PRODUCT_SOONG_NAMESPACES += \
     vendor/google/camera \
@@ -36,8 +41,7 @@
 # Calibration tool for debug builds
 PRODUCT_PACKAGES_DEBUG += tarasque_test
 PRODUCT_PACKAGES_DEBUG += ProtoCalibGenerator
-
-endif  # vendor/google/camera check
+endif  # RELEASE_PIXEL_CAMERA_ENABLE_PREBUILT check
 
 # Init-time log settings for Google 3A
 PRODUCT_PACKAGES += libg3a_standalone_gabc_rc
diff --git a/gpu/gpu.mk b/gpu/gpu.mk
index 1062ef7..4b11e13 100644
--- a/gpu/gpu.mk
+++ b/gpu/gpu.mk
@@ -8,9 +8,9 @@
 PRODUCT_PACKAGES += pixel_gralloc_mapper
 
 ifeq ($(USE_MAPPER5), true)
-$(call soong_config_set,arm_gralloc,mapper_version,mapper5)
+$(call soong_config_set,pixel_gralloc,mapper_version,mapper5)
 $(call soong_config_set,aion_buffer,mapper_version,mapper5)
 else
-$(call soong_config_set,arm_gralloc,mapper_version,mapper4)
+$(call soong_config_set,pixel_gralloc,mapper_version,mapper4)
 $(call soong_config_set,aion_buffer,mapper_version,mapper4)
 endif
diff --git a/modem/dump_modemlog/Android.bp b/modem/dump_modemlog/Android.bp
index aca7b20..f509320 100644
--- a/modem/dump_modemlog/Android.bp
+++ b/modem/dump_modemlog/Android.bp
@@ -1,12 +1,12 @@
 package {
-    default_applicable_licenses: [ "Android-Apache-2.0" ],
+    default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
-sh_binary {
-    name: "dump_modem.sh",
-    src: "dump_modem.sh",
+rust_binary {
+    name: "dump_modem",
+    srcs: ["dump_modem.rs"],
     vendor: true,
-    sub_dir: "dump",
+    relative_install_path: "dump",
 }
 
 // Modem Log Dumper
@@ -30,10 +30,10 @@
 
 cc_library {
     name: "modem_log_dumper",
-    srcs: [ "modem_log_dumper.cpp" ],
-    defaults: [ "modem_log_dumper_defaults" ],
+    srcs: ["modem_log_dumper.cpp"],
+    defaults: ["modem_log_dumper_defaults"],
     export_shared_lib_headers: modem_log_dumper_public_deps,
-    export_include_dirs: [ "include" ],
+    export_include_dirs: ["include"],
     vendor_available: true,
 }
 
@@ -41,7 +41,7 @@
 
 cc_binary {
     name: "dump_modemlog",
-    srcs: [ "dump_modemlog.cpp" ],
+    srcs: ["dump_modemlog.cpp"],
     cflags: [
         "-Wall",
         "-Wextra",
@@ -60,7 +60,7 @@
 
 cc_test {
     name: "dump_modemlog_test",
-    srcs: [ "modem_log_dumper_test.cpp" ],
+    srcs: ["modem_log_dumper_test.cpp"],
     defaults: [
         "modem_log_dumper_defaults",
         "modem_android_property_manager_fake_defaults",
diff --git a/modem/dump_modemlog/dump_modem.rs b/modem/dump_modemlog/dump_modem.rs
new file mode 100644
index 0000000..d9af7eb
--- /dev/null
+++ b/modem/dump_modemlog/dump_modem.rs
@@ -0,0 +1,109 @@
+// Copyright 2024 Google LLC
+
+//! The dump_modem binary is used to capture kernel/userspace logs in bugreport
+
+use std::fs;
+
+const MODEM_STAT: &str = "/data/vendor/modem_stat/debug.txt";
+const SSRDUMP_DIR: &str = "/data/vendor/ssrdump";
+const RFSD_ERR_LOG_DIR: &str = "/data/vendor/log/rfsd";
+const WAKEUP_EVENTS: &str = "/sys/devices/platform/cpif/wakeup_events";
+const CPIF_LOGBUFFER: &str = "/dev/logbuffer_cpif";
+const PCIE_EVENT_STATS: &str = "/sys/devices/platform/cpif/modem/pcie_event_stats";
+
+fn handle_io_error(file: &str, err: std::io::Error) {
+    match err.kind() {
+        std::io::ErrorKind::NotFound => println!("{file} not found!"),
+        std::io::ErrorKind::PermissionDenied => println!("Permission denied to access {file}"),
+        _ => println!("I/O error accessing {file}: {err}"),
+    }
+}
+
+fn print_file(file: &str) -> Result<(), std::io::Error> {
+    fs::metadata(file)?;
+
+    let data = fs::read_to_string(file)?;
+
+    if data.is_empty() {
+        println!("{file} is empty");
+    } else {
+        print!("{data}");
+    }
+
+    Ok(())
+}
+
+fn print_file_and_handle_error(file: &str) {
+    if let Err(err) = print_file(file) {
+        handle_io_error(file, err);
+    }
+}
+
+fn print_matching_files_in_dir(dir: &str, filename: &str) {
+    let Ok(entries) = fs::read_dir(dir) else {
+        return println!("Cannot open directory {dir}");
+    };
+
+    for entry in entries {
+        let Ok(entry) = entry else {
+            continue;
+        };
+        if entry.path().is_file() && entry.file_name().to_string_lossy().starts_with(filename) {
+            if let Some(path_str) = entry.path().to_str() {
+                println!("{}", path_str);
+                print_file_and_handle_error(path_str);
+            }
+        }
+    }
+}
+
+// Capture modem stat log if it exists
+fn modem_stat() {
+    println!("------ Modem Stat ------");
+    print_file_and_handle_error(MODEM_STAT);
+    println!();
+}
+
+// Capture crash signatures from all modem crashes
+fn modem_ssr_history() {
+    println!("------ Modem SSR history ------");
+    print_matching_files_in_dir(SSRDUMP_DIR, "crashinfo_modem");
+    println!();
+}
+
+// Capture rfsd error logs from all existing log files
+fn rfsd_error_log() {
+    println!("------ RFSD error log ------");
+    print_matching_files_in_dir(RFSD_ERR_LOG_DIR, "rfslog");
+    println!();
+}
+
+// Capture modem wakeup events if the sysfs attribute exists
+fn wakeup_events() {
+    println!("------ Wakeup event counts ------");
+    print_file_and_handle_error(WAKEUP_EVENTS);
+    println!();
+}
+
+// Capture kernel driver logbuffer if it exists
+fn cpif_logbuffer() {
+    println!("------ CPIF Logbuffer ------");
+    print_file_and_handle_error(CPIF_LOGBUFFER);
+    println!();
+}
+
+// Capture modem pcie stats if the sysfs attribute exists
+fn pcie_event_stats() {
+    println!("------ PCIe event stats ------");
+    print_file_and_handle_error(PCIE_EVENT_STATS);
+    println!();
+}
+
+fn main() {
+    modem_stat();
+    modem_ssr_history();
+    rfsd_error_log();
+    wakeup_events();
+    cpif_logbuffer();
+    pcie_event_stats();
+}
diff --git a/modem/dump_modemlog/dump_modem.sh b/modem/dump_modemlog/dump_modem.sh
deleted file mode 100644
index d1a535d..0000000
--- a/modem/dump_modemlog/dump_modem.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/vendor/bin/sh
-
-WAKEUP_EVENTS_FILE=/sys/devices/platform/cpif/wakeup_events
-CPIF_LOGBUFFER=/dev/logbuffer_cpif
-PCIE_EVENT_STATS=/sys/devices/platform/cpif/modem/pcie_event_stats
-
-echo "------ Modem Stat ------"
-cat /data/vendor/modem_stat/debug.txt
-
-echo "\n------ Modem SSR history ------"
-for f in $(ls /data/vendor/ssrdump/crashinfo_modem*); do
-  echo $f
-  cat $f
-done
-
-echo "\n------ RFSD error log ------"
-for f in $(ls /data/vendor/log/rfsd/rfslog_*); do
-  echo $f
-  cat $f
-done
-
-if [ -e $WAKEUP_EVENTS_FILE ]
-then
-  echo "\n------ Wakeup event counts ------"
-  echo $WAKEUP_EVENTS_FILE
-  cat $WAKEUP_EVENTS_FILE
-fi
-
-if [ -e $CPIF_LOGBUFFER ]
-then
-  echo "\n------ CPIF Logbuffer ------"
-  echo $CPIF_LOGBUFFER
-  cat $CPIF_LOGBUFFER
-fi
-
-if [ -e $PCIE_EVENT_STATS ]
-then
-  echo "\n------ PCIe event stats ------"
-  echo $PCIE_EVENT_STATS
-  cat $PCIE_EVENT_STATS
-fi
diff --git a/modem/dump_modemlog/dump_modemlog.mk b/modem/dump_modemlog/dump_modemlog.mk
index 5e91ab7..c96e729 100644
--- a/modem/dump_modemlog/dump_modemlog.mk
+++ b/modem/dump_modemlog/dump_modemlog.mk
@@ -1,5 +1,5 @@
 BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/modem/dump_modemlog/sepolicy
 
-PRODUCT_PACKAGES += dump_modem.sh
+PRODUCT_PACKAGES += dump_modem
 PRODUCT_PACKAGES += dump_modemlog
 
diff --git a/modem/dump_modemlog/sepolicy/file_contexts b/modem/dump_modemlog/sepolicy/file_contexts
index 29315e9..6d5c082 100644
--- a/modem/dump_modemlog/sepolicy/file_contexts
+++ b/modem/dump_modemlog/sepolicy/file_contexts
@@ -1,3 +1,3 @@
-/vendor/bin/dump/dump_modem\.sh      u:object_r:dump_modem_exec:s0
+/vendor/bin/dump/dump_modem          u:object_r:dump_modem_exec:s0
 /vendor/bin/dump/dump_modemlog       u:object_r:dump_modemlog_exec:s0
 
diff --git a/performance/OWNERS b/performance/OWNERS
new file mode 100644
index 0000000..7ee3645
--- /dev/null
+++ b/performance/OWNERS
@@ -0,0 +1,4 @@
+wvw@google.com
+paillon@google.com
+jenhaochen@google.com
+liumartin@google.com
diff --git a/performance/perf.mk b/performance/perf.mk
index dfbdb5b..ad4011a 100644
--- a/performance/perf.mk
+++ b/performance/perf.mk
@@ -1,3 +1,7 @@
 BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/performance/sepolicy
 
 PRODUCT_PACKAGES += dump_perf
+
+# Ensure enough free space to create zram backing device
+PRODUCT_PRODUCT_PROPERTIES += \
+    ro.zram_backing_device_min_free_mb=1536
diff --git a/sensors/dump_sensors.cpp b/sensors/dump_sensors.cpp
index 58d63e9..4c406ce 100644
--- a/sensors/dump_sensors.cpp
+++ b/sensors/dump_sensors.cpp
@@ -26,7 +26,8 @@
     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 ||
+        if (hwRev.find("DEV") != std::string::npos ||
+            hwRev.find("PROTO") != std::string::npos ||
             hwRev.find("EVT") != std::string::npos ||
             hwRev.find("DVT") != std::string::npos ||
             hwRev.find("PVT") != std::string::npos) {
diff --git a/touch/gti/dump_gti0.sh b/touch/gti/dump_gti0.sh
index a3af3d7..facb531 100644
--- a/touch/gti/dump_gti0.sh
+++ b/touch/gti/dump_gti0.sh
@@ -8,6 +8,11 @@
 heatmap_path=$path
 fi
 
+if [[ -f "${procfs_path}/dump" ]]; then
+  echo "------ Dump ------"
+  cat ${procfs_path}/dump
+fi
+
 echo "------ Force Touch Active ------"
 result=$( cat "$path/force_active" 2>&1 )
 if [ $? -eq 0 ]; then
@@ -60,10 +65,5 @@
 echo "------ Self Test ------"
 cat $path/self_test
 
-if [[ -f "${procfs_path}/dump" ]]; then
-  echo "------ Dump ------"
-  cat ${procfs_path}/dump
-fi
-
 echo "------ Disable Force Touch Active ------"
 echo 0 > $path/force_active
diff --git a/touch/gti/dump_gti1.sh b/touch/gti/dump_gti1.sh
index 297ad44..eabd6d6 100644
--- a/touch/gti/dump_gti1.sh
+++ b/touch/gti/dump_gti1.sh
@@ -8,6 +8,11 @@
 heatmap_path=$path
 fi
 
+if [[ -f "${procfs_path}/dump" ]]; then
+  echo "------ Dump ------"
+  cat ${procfs_path}/dump
+fi
+
 echo "------ Force Touch Active ------"
 result=$( cat "$path/force_active" 2>&1 )
 if [ $? -eq 0 ]; then
@@ -60,10 +65,5 @@
 echo "------ Self Test ------"
 cat $path/self_test
 
-if [[ -f "${procfs_path}/dump" ]]; then
-  echo "------ Dump ------"
-  cat ${procfs_path}/dump
-fi
-
 echo "------ Disable Force Touch Active ------"
 echo 0 > $path/force_active
diff --git a/widevine/sepolicy/file.te b/widevine/sepolicy/file.te
new file mode 100644
index 0000000..a1e4e0e
--- /dev/null
+++ b/widevine/sepolicy/file.te
@@ -0,0 +1,3 @@
+# Widevine DRM
+type mediadrm_vendor_data_file, file_type, data_file_type;
+
diff --git a/widevine/sepolicy/file_contexts b/widevine/sepolicy/file_contexts
new file mode 100644
index 0000000..92aed3c
--- /dev/null
+++ b/widevine/sepolicy/file_contexts
@@ -0,0 +1,5 @@
+/vendor/bin/hw/android\.hardware\.drm-service\.widevine          u:object_r:hal_drm_widevine_exec:s0
+/vendor/bin/hw/android\.hardware\.drm-service\.clearkey          u:object_r:hal_drm_clearkey_exec:s0
+
+# Data
+/data/vendor/mediadrm(/.*)?                                      u:object_r:mediadrm_vendor_data_file:s0
diff --git a/widevine/sepolicy/hal_drm_clearkey.te b/widevine/sepolicy/hal_drm_clearkey.te
new file mode 100644
index 0000000..81ecfb9
--- /dev/null
+++ b/widevine/sepolicy/hal_drm_clearkey.te
@@ -0,0 +1,5 @@
+type hal_drm_clearkey, domain;
+type hal_drm_clearkey_exec, vendor_file_type, exec_type, file_type;
+init_daemon_domain(hal_drm_clearkey)
+
+#TODO: snehalreddy@ add sepolicy
diff --git a/widevine/sepolicy/hal_drm_widevine.te b/widevine/sepolicy/hal_drm_widevine.te
new file mode 100644
index 0000000..41e395a
--- /dev/null
+++ b/widevine/sepolicy/hal_drm_widevine.te
@@ -0,0 +1,5 @@
+type hal_drm_widevine, domain;
+type hal_drm_widevine_exec, vendor_file_type, exec_type, file_type;
+init_daemon_domain(hal_drm_widevine)
+
+#TODO: snehalreddy@ add sepolicy
diff --git a/widevine/sepolicy/service_contexts b/widevine/sepolicy/service_contexts
new file mode 100644
index 0000000..6989dde
--- /dev/null
+++ b/widevine/sepolicy/service_contexts
@@ -0,0 +1 @@
+android.hardware.drm.IDrmFactory/widevine    u:object_r:hal_drm_service:s0
diff --git a/widevine/widevine_v2.mk b/widevine/widevine_v2.mk
new file mode 100644
index 0000000..5cd914b
--- /dev/null
+++ b/widevine/widevine_v2.mk
@@ -0,0 +1,2 @@
+include device/google/gs-common/widevine/widevine.mk
+BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/widevine/sepolicy/
\ No newline at end of file
diff --git a/wireless_charger/compatibility_matrix.xml b/wireless_charger/compatibility_matrix.xml
index b760b1d..5185344 100644
--- a/wireless_charger/compatibility_matrix.xml
+++ b/wireless_charger/compatibility_matrix.xml
@@ -9,7 +9,7 @@
     </hal>
     <hal format="aidl" optional="true">
         <name>vendor.google.wireless_charger.service</name>
-        <version>1</version>
+        <version>1-2</version>
         <interface>
             <name>IWlcService</name>
             <instance>default</instance>