From 29e9774d6422ee3e289870a05ac784f44f1376b5 Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Wed, 15 Feb 2023 15:26:31 -0800 Subject: [PATCH 01/74] Move thermal utils to hardware/interfaces Bug: b/269370789 Test: m Change-Id: If7628b88a0b5a8d933dd0431eac2d3663649e834 --- usb/usb/Android.bp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 07e66ead..7a60d900 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -57,7 +57,7 @@ cc_binary { static_libs: [ "libpixelusb-aidl", "libpixelstats", - "libpixelthermalwrapper", + "libthermalutils", ], export_shared_lib_headers: [ "android.frameworks.stats-V1-ndk", From e8d9ec6f0b73a867ad6800424e1b1c01d1b094fc Mon Sep 17 00:00:00 2001 From: Cynthia Wasonga Date: Wed, 21 Dec 2022 07:11:59 +0000 Subject: [PATCH 02/74] Fix gs201 preinstall config module loading on device Adds fix for ag/20438528 Bug: 238970256 Test: Verify that TestRcsApp and BatteryStatsViewer are not installed on clone profile Change-Id: I58e832866c67ff71dbda01f7b4952fe842494dd3 --- Android.bp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Android.bp b/Android.bp index 9b83b174..150a519c 100644 --- a/Android.bp +++ b/Android.bp @@ -34,3 +34,11 @@ license { "NOTICE", ], } + +prebuilt_etc { + name: "preinstalled-packages-product-gs201-device-debug.xml", + src: "preinstalled-packages-product-gs201-device-debug.xml", + product_specific: true, + sub_dir: "sysconfig", + filename_from_src: true, +} From 923c100ba6100f7c2a0ec3619e7700a7018e6e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Wagner?= Date: Tue, 27 Dec 2022 13:47:39 +0000 Subject: [PATCH 03/74] Update Mali DDK to r40 : Sysprop configuration settings Expose DDK's dynamic configuration options through the Android Sysprop interface, following recommendations from Arm's Android Integration Manual. b/261718474 Change-Id: Ie2135862c61fada85c4e9cfa97aecbf635768721 --- device.mk | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/device.mk b/device.mk index ba61733c..82f680b5 100644 --- a/device.mk +++ b/device.mk @@ -224,6 +224,13 @@ PRODUCT_PACKAGES += \ PRODUCT_VENDOR_PROPERTIES += \ ro.hardware.vulkan=mali +# Mali Configuration Properties +# b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 +PRODUCT_VENDOR_PROPERTIES += \ + vendor.mali.protected_max_core_count=1 \ + vendor.mali.protected_tls_max=67108864 \ + vendor.mali.platform_agt_frequency_khz=24576 + ifeq ($(USE_SWIFTSHADER),true) PRODUCT_PACKAGES += \ libGLESv1_CM_swiftshader \ From e573bfd11ff2680f5b645a8c260faf3e712f5f49 Mon Sep 17 00:00:00 2001 From: Armelle Laine Date: Mon, 12 Dec 2022 01:08:09 +0000 Subject: [PATCH 04/74] Add metrics to the gs201 makefile Bug: None Test: TBD Change-Id: I516129e1edd537f47d35e54834fdcdc96bab5354 --- device.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/device.mk b/device.mk index 6d651228..a57b07fb 100644 --- a/device.mk +++ b/device.mk @@ -834,11 +834,11 @@ PRODUCT_PACKAGES += \ securedpud.slider # Trusty Metrics Daemon -#PRODUCT_SOONG_NAMESPACES += \ -# vendor/google/trusty/common -# -#PRODUCT_PACKAGES += \ -# trusty_metricsd +PRODUCT_SOONG_NAMESPACES += \ + vendor/google/trusty/common + +PRODUCT_PACKAGES += \ + trusty_metricsd $(call soong_config_set,google_displaycolor,displaycolor_platform,gs201) PRODUCT_PACKAGES += \ From 1e26affe87302e85d458c3a6caf3b06972ad32c8 Mon Sep 17 00:00:00 2001 From: Armelle Laine Date: Sun, 5 Feb 2023 22:43:23 +0000 Subject: [PATCH 05/74] trusty: Add trusty_stats_test Test: TBD Bug: None Change-Id: If3ad0e5eec831a8f5632504453994f29f350224c --- device.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index a57b07fb..2d9a8586 100644 --- a/device.mk +++ b/device.mk @@ -824,8 +824,10 @@ $(call inherit-product, system/core/trusty/trusty-base.mk) include device/google/gs-common/trusty/trusty.mk # Trusty unit test tool -PRODUCT_PACKAGES_DEBUG += trusty-ut-ctrl \ - tipc-test +PRODUCT_PACKAGES_DEBUG += \ + trusty-ut-ctrl \ + tipc-test \ + trusty_stats_test \ include device/google/gs101/confirmationui/confirmationui.mk From 43730de70c29a55ffc9508d58e2f918df199799a Mon Sep 17 00:00:00 2001 From: Adam Shih Date: Fri, 24 Mar 2023 12:42:07 +0800 Subject: [PATCH 06/74] use radio dump in gs-common Bug: 273380509 Test: adb bugreport Change-Id: Id60eefa3a78186f2bf093295490fb7d2524bf80b --- device.mk | 1 + dumpstate/Dumpstate.cpp | 143 +--------------------------------------- dumpstate/Dumpstate.h | 10 --- 3 files changed, 2 insertions(+), 152 deletions(-) diff --git a/device.mk b/device.mk index 756539f5..89e8a5e4 100644 --- a/device.mk +++ b/device.mk @@ -28,6 +28,7 @@ include device/google/gs-common/display/dump.mk include device/google/gs-common/camera/dump.mk include device/google/gs-common/gxp/dump.mk include device/google/gs-common/gps/dump/log.mk +include device/google/gs-common/radio/dump.mk include device/google/gs-common/umfw_stat/umfw_stat.mk TARGET_BOARD_PLATFORM := gs201 diff --git a/dumpstate/Dumpstate.cpp b/dumpstate/Dumpstate.cpp index 8ffb682f..f516e1d4 100644 --- a/dumpstate/Dumpstate.cpp +++ b/dumpstate/Dumpstate.cpp @@ -32,14 +32,6 @@ #include "DumpstateUtil.h" -#define RIL_LOG_DIRECTORY "/data/vendor/radio" -#define RIL_LOG_DIRECTORY_PROPERTY "persist.vendor.ril.log.base_dir" -#define RIL_LOG_NUMBER_PROPERTY "persist.vendor.ril.log.num_file" - -#define TCPDUMP_LOG_DIRECTORY "/data/vendor/tcpdump_logger/logs" -#define TCPDUMP_NUMBER_BUGREPORT "persist.vendor.tcpdump.log.br_num" -#define TCPDUMP_PERSIST_PROPERTY "persist.vendor.tcpdump.log.alwayson" - using android::os::dumpstate::CommandOptions; using android::os::dumpstate::DumpFileToFd; using android::os::dumpstate::PropertiesHelper; @@ -50,119 +42,10 @@ namespace android { namespace hardware { namespace dumpstate { -#define EXTENDED_LOG_PREFIX "extended_log_" -#define RIL_LOG_PREFIX "rild.log." -#define BUFSIZE 65536 -#define TCPDUMP_LOG_PREFIX "tcpdump" - typedef std::chrono::time_point timepoint_t; const char kVerboseLoggingProperty[] = "persist.vendor.verbose_logging_enabled"; -void Dumpstate::dumpLogs(int fd, std::string srcDir, std::string destDir, int maxFileNum, - const char *logPrefix) { - struct dirent **dirent_list = NULL; - int num_entries = scandir(srcDir.c_str(), - &dirent_list, - 0, - (int (*)(const struct dirent **, const struct dirent **)) alphasort); - if (!dirent_list) { - return; - } else if (num_entries <= 0) { - return; - } - - int copiedFiles = 0; - - for (int i = num_entries - 1; i >= 0; i--) { - ALOGD("Found %s\n", dirent_list[i]->d_name); - - if (0 != strncmp(dirent_list[i]->d_name, logPrefix, strlen(logPrefix))) { - continue; - } - - if ((copiedFiles >= maxFileNum) && (maxFileNum != -1)) { - ALOGD("Skipped %s\n", dirent_list[i]->d_name); - continue; - } - - copiedFiles++; - - CommandOptions options = CommandOptions::WithTimeout(120).Build(); - std::string srcLogFile = srcDir + "/" + dirent_list[i]->d_name; - std::string destLogFile = destDir + "/" + dirent_list[i]->d_name; - - std::string copyCmd = "/vendor/bin/cp " + srcLogFile + " " + destLogFile; - - ALOGD("Copying %s to %s\n", srcLogFile.c_str(), destLogFile.c_str()); - RunCommandToFd(fd, "CP LOGS", { "/vendor/bin/sh", "-c", copyCmd.c_str() }, options); - } - - while (num_entries--) { - free(dirent_list[num_entries]); - } - - free(dirent_list); -} - -void Dumpstate::dumpRilLogs(int fd, std::string destDir) { - std::string rilLogDir = - ::android::base::GetProperty(RIL_LOG_DIRECTORY_PROPERTY, RIL_LOG_DIRECTORY); - - int maxFileNum = ::android::base::GetIntProperty(RIL_LOG_NUMBER_PROPERTY, 50); - - const std::string currentLogDir = rilLogDir + "/cur"; - const std::string previousLogDir = rilLogDir + "/prev"; - const std::string currentDestDir = destDir + "/cur"; - const std::string previousDestDir = destDir + "/prev"; - - RunCommandToFd(fd, "MKDIR RIL CUR LOG", {"/vendor/bin/mkdir", "-p", currentDestDir.c_str()}, - CommandOptions::WithTimeout(2).Build()); - RunCommandToFd(fd, "MKDIR RIL PREV LOG", {"/vendor/bin/mkdir", "-p", previousDestDir.c_str()}, - CommandOptions::WithTimeout(2).Build()); - - dumpLogs(fd, currentLogDir, currentDestDir, maxFileNum, RIL_LOG_PREFIX); - dumpLogs(fd, previousLogDir, previousDestDir, maxFileNum, RIL_LOG_PREFIX); -} - -void copyFile(std::string srcFile, std::string destFile) { - uint8_t buffer[BUFSIZE]; - ssize_t size; - - int fdSrc = open(srcFile.c_str(), O_RDONLY); - if (fdSrc < 0) { - ALOGD("Failed to open source file %s\n", srcFile.c_str()); - return; - } - - int fdDest = open(destFile.c_str(), O_WRONLY | O_CREAT, 0666); - if (fdDest < 0) { - ALOGD("Failed to open destination file %s\n", destFile.c_str()); - close(fdSrc); - return; - } - - ALOGD("Copying %s to %s\n", srcFile.c_str(), destFile.c_str()); - while ((size = TEMP_FAILURE_RETRY(read(fdSrc, buffer, BUFSIZE))) > 0) { - TEMP_FAILURE_RETRY(write(fdDest, buffer, size)); - } - - close(fdDest); - close(fdSrc); -} - -void dumpNetmgrLogs(std::string destDir) { - const std::vector netmgrLogs - { - "/data/vendor/radio/metrics_data", - "/data/vendor/radio/omadm_logs.txt", - "/data/vendor/radio/power_anomaly_data.txt", - }; - for (const auto& logFile : netmgrLogs) { - copyFile(logFile, destDir + "/" + basename(logFile.c_str())); - } -} - timepoint_t startSection(int fd, const std::string §ionName) { ATRACE_BEGIN(sectionName.c_str()); ::android::base::WriteStringToFd( @@ -190,11 +73,7 @@ Dumpstate::Dumpstate() { "wlan", [this](int fd) { dumpWlanSection(fd); } }, { "power", [this](int fd) { dumpPowerSection(fd); } }, { "pixel-trace", [this](int fd) { dumpPixelTraceSection(fd); } }, - }, - mLogSections{ - { "radio", [this](int fd, const std::string &destDir) { dumpRadioLogs(fd, destDir); } }, - } { -} + } {} // Dump data requested by an argument to the "dump" interface, or help info // if the specified section is not supported. @@ -464,17 +343,6 @@ void Dumpstate::dumpPowerSection(int fd) { } -void Dumpstate::dumpRadioLogs(int fd, const std::string &destDir) { - std::string tcpdumpLogDir = TCPDUMP_LOG_DIRECTORY; - bool tcpdumpEnabled = ::android::base::GetBoolProperty(TCPDUMP_PERSIST_PROPERTY, false); - - if (tcpdumpEnabled) { - dumpLogs(fd, tcpdumpLogDir, destDir, ::android::base::GetIntProperty(TCPDUMP_NUMBER_BUGREPORT, 5), TCPDUMP_LOG_PREFIX); - } - dumpRilLogs(fd, destDir); - dumpNetmgrLogs(destDir); -} - void Dumpstate::dumpLogSection(int fd, int fd_bin) { std::string logDir = MODEM_LOG_DIRECTORY; @@ -485,15 +353,6 @@ void Dumpstate::dumpLogSection(int fd, int fd_bin) dumpTextSection(fd, kAllSections); - // Dump all module logs - if (!PropertiesHelper::IsUserBuild()) { - for (const auto §ion : mLogSections) { - auto startTime = startSection(fd, section.first); - section.second(fd, logAllDir); - endSection(fd, section.first, startTime); - } - } - RunCommandToFd(fd, "TAR LOG", {"/vendor/bin/tar", "cvf", logCombined.c_str(), "-C", logAllDir.c_str(), "."}, CommandOptions::WithTimeout(20).Build()); RunCommandToFd(fd, "CHG PERM", {"/vendor/bin/chmod", "a+w", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build()); diff --git a/dumpstate/Dumpstate.h b/dumpstate/Dumpstate.h index 3065dda5..a6d6bcf6 100644 --- a/dumpstate/Dumpstate.h +++ b/dumpstate/Dumpstate.h @@ -43,10 +43,6 @@ class Dumpstate : public BnDumpstateDevice { const std::string kAllSections = "all"; std::vector>> mTextSections; - std::vector>> mLogSections; - - void dumpLogs(int fd, std::string srcDir, std::string destDir, int maxFileNum, - const char *logPrefix); void dumpTextSection(int fd, std::string const& sectionName); @@ -58,12 +54,6 @@ class Dumpstate : public BnDumpstateDevice { void dumpLogSection(int fd, int fdModem); - // Log sections to be dumped individually into dumpstate_board.bin - void dumpRadioLogs(int fd, const std::string &destDir); - - // Hybrid and binary sections that require an additional file descriptor - void dumpRilLogs(int fd, std::string destDir); - //bool getVerboseLoggingEnabledImpl(); //::ndk::ScopedAStatus dumpstateBoardImpl(const int fd, const bool full); }; From c223a4903851d1888aa653d686f2e99f939d46c0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 15 Mar 2023 12:49:37 +0000 Subject: [PATCH 07/74] Fix mali memory protection sysprop names The previous patch did not use the `base_*` prefix, meaning the driver kept using the default configuration. Bug: b/272740524 Test: CtsDeqpTestCases (dEQP-VK.protected_memory.stack.stacksize_*) Change-Id: I71aee32590e3878ada69533daeb2b629eb4a42fc --- device.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device.mk b/device.mk index 89e8a5e4..bb2041fd 100644 --- a/device.mk +++ b/device.mk @@ -235,8 +235,8 @@ PRODUCT_VENDOR_PROPERTIES += \ # Mali Configuration Properties # b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 PRODUCT_VENDOR_PROPERTIES += \ - vendor.mali.protected_max_core_count=1 \ - vendor.mali.protected_tls_max=67108864 \ + vendor.mali.base_protected_max_core_count=1 \ + vendor.mali.base_protected_tls_max=67108864 \ vendor.mali.platform_agt_frequency_khz=24576 ifeq ($(USE_SWIFTSHADER),true) From 83086bd0d82a14dab328d72646eaf121e878ebe4 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 28 Mar 2023 11:13:55 +0900 Subject: [PATCH 08/74] Add BOARD_WLAN_CHIP to soong config wcn6740 uses a new implementation for libwifi-hal-qcom. We need a soong config variable for BOARD_WLAN_CHIP to switch the implementation. Bug: 273376293 Test: m libwifi-hal (with gs201 target) Change-Id: Iddeb4e76be213fde2d1bb4dbd614a1213bc35e89 --- wifi/qcom/BoardConfig-wifi.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wifi/qcom/BoardConfig-wifi.mk b/wifi/qcom/BoardConfig-wifi.mk index dcc75a9c..6546ce44 100644 --- a/wifi/qcom/BoardConfig-wifi.mk +++ b/wifi/qcom/BoardConfig-wifi.mk @@ -46,3 +46,6 @@ BOARD_HOSTAPD_CONFIG_80211W_MFP_OPTIONAL := true PRODUCT_COPY_FILES += \ $(LOCAL_WIFI_PATH)/wpa_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant_overlay.conf \ $(LOCAL_WIFI_PATH)/p2p_supplicant_overlay.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/p2p_supplicant_overlay.conf + +# Add BOARD_WLAN_CHIP to soong_config +$(call soong_config_set,qcom_wifi,board_wlan_chip,wcn6740) \ No newline at end of file From aa5b1036db7f53d253d533cded53654974f773c2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 6 Apr 2023 15:19:48 +0000 Subject: [PATCH 09/74] Define mali configuration path explicitly This avoids mali trying to read `/data/data/com.mali.testjava` for its debug config. Bug: b/205779871 Test: manual - reboot device and check the absence of AVC denials Change-Id: Id168e9ce380eb6d3657a83e74ec8afd52bbd584e --- device.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/device.mk b/device.mk index e71b9951..7bc49203 100644 --- a/device.mk +++ b/device.mk @@ -236,6 +236,8 @@ PRODUCT_VENDOR_PROPERTIES += \ # Mali Configuration Properties # b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 PRODUCT_VENDOR_PROPERTIES += \ + vendor.mali.platform.config=/vendor/etc/mali/platform.config \ + vendor.mali.debug.config=/vendor/etc/mali/debug.config \ vendor.mali.base_protected_max_core_count=1 \ vendor.mali.base_protected_tls_max=67108864 \ vendor.mali.platform_agt_frequency_khz=24576 From 2ffafe00cc4b4184c4af3191d291aeef7b1a5c79 Mon Sep 17 00:00:00 2001 From: chenkris Date: Mon, 15 May 2023 10:34:10 +0000 Subject: [PATCH 10/74] Remove unused udfps make files Bug: 270657514 Test: make Change-Id: Ie1e18bc2bc3df615f0ce9833fed76b7508791bd5 --- fingerprint/udfps.mk | 28 ---------------------------- fingerprint/udfps_factory.mk | 22 ---------------------- 2 files changed, 50 deletions(-) delete mode 100644 fingerprint/udfps.mk delete mode 100644 fingerprint/udfps_factory.mk diff --git a/fingerprint/udfps.mk b/fingerprint/udfps.mk deleted file mode 100644 index 61f138f6..00000000 --- a/fingerprint/udfps.mk +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (C) 2020 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. -# - -PRODUCT_COPY_FILES += \ - frameworks/native/data/etc/android.hardware.fingerprint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.fingerprint.xml - -# Include the Goodix AIDL HAL namespaces. -PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_trusty -PRODUCT_SOONG_NAMESPACES += vendor/goodix/udfps/g6_aidl_trusty - -$(call soong_config_set,fp_hal_feature,biometric_suez_support,true) - -PRODUCT_PACKAGES += \ - android.hardware.biometrics.fingerprint@2.1-service.goodix \ - android.hardware.biometrics.fingerprint-service.goodix diff --git a/fingerprint/udfps_factory.mk b/fingerprint/udfps_factory.mk deleted file mode 100644 index 41aebe08..00000000 --- a/fingerprint/udfps_factory.mk +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (C) 2020 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. -# - -PRODUCT_PACKAGES += \ - GF_delmar_factory \ - udfps_test - -PRODUCT_PROPERTY_OVERRIDES += \ - gf.debug.dump_data=1 From 7c4c316fc07526efb9e956cc55c82e52b2f6c3ef Mon Sep 17 00:00:00 2001 From: Kevin DuBois Date: Mon, 24 Apr 2023 23:25:47 +0000 Subject: [PATCH 11/74] device.mk: add gpu_probe service. Adds a service that uploads gpu counter data to Perfetto. Service must be started via "start gpu_probe" and the Perfetto config must request counters via "gpu.counters". Bug: 26766418 Test: see perfetto events produced with this service. Change-Id: I40c3152138bd3eb8252741e187586379ce659ac6 --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index ed62dfba..37528d9e 100644 --- a/device.mk +++ b/device.mk @@ -225,6 +225,7 @@ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) include device/google/gs101/neuralnetwork/neuralnetwork.mk +include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_todx_mali_csffw.bin \ libGLES_mali \ From 7a51d8192278075abf9c74969e766f6d74e95e63 Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Fri, 23 Jun 2023 13:22:45 +0000 Subject: [PATCH 12/74] Remove settings for old ArmNN HIDL backend Compile ArmNN shim over the support library. Remove settings for the old HIDL backend. The new ones will be in the gs-common folder. Test: Local run of CtsNNAPITestCases Test: Local run of VtsHalNeuralnetworksTargetTest Test: Local run of MLTS Benchmark Bug: 283724775 Change-Id: I3652eceb14d06a3e909444edc21ad86d9378bc6c --- BoardConfig-common.mk | 10 ---------- device.mk | 5 ----- manifest-gralloc3.xml | 10 ---------- manifest.xml | 10 ---------- 4 files changed, 35 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index f6804417..723b6b6e 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -352,16 +352,6 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 -# NeuralNetworks -GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) -GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zebu/prebuilts/libs) -ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) -ARMNN_COMPUTE_CL_ENABLE := 1 -else -ARMNN_COMPUTE_CL_ENABLE := 0 -endif -ARMNN_COMPUTE_NEON_ENABLE := 1 - # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index 30e1ef9e..b9dcf4cd 100644 --- a/device.mk +++ b/device.mk @@ -225,8 +225,6 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) -include device/google/gs101/neuralnetwork/neuralnetwork.mk - include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_todx_mali_csffw.bin \ @@ -1000,9 +998,6 @@ PRODUCT_COPY_FILES += \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.cfg:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.cfg \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.nprf:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.nprf \ -# ARM NN files -ARMNN_COMPUTE_CL_ENABLE := 1 - # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index dc91529d..0427aa5e 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -82,16 +82,6 @@ default - - android.hardware.neuralnetworks - hwbinder - 1.3 - - IDevice - google-armnn - - @1.3::IDevice/google-armnn - android.hardware.neuralnetworks hwbinder diff --git a/manifest.xml b/manifest.xml index 90af32bd..b6e6396b 100644 --- a/manifest.xml +++ b/manifest.xml @@ -13,16 +13,6 @@ hwbinder @1.2::IBootControl/default - - android.hardware.neuralnetworks - hwbinder - 1.3 - - IDevice - google-armnn - - @1.3::IDevice/google-armnn - com.google.input.algos.spd From a15331d5744dd7b5ca9a9ee3d9f356aff067631e Mon Sep 17 00:00:00 2001 From: Android Culprit Assistant Date: Wed, 12 Jul 2023 20:43:46 +0000 Subject: [PATCH 13/74] Revert "Remove settings for old ArmNN HIDL backend" This revert was created by Android Culprit Assistant. The culprit was identified in the following culprit search session (http://go/aca-get/123b2665-83ef-4fd0-904d-a0d8c5782db9). Change-Id: Ib69a94a6a2a8a087e3c2e7e5539045ec751e4a8f --- BoardConfig-common.mk | 10 ++++++++++ device.mk | 5 +++++ manifest-gralloc3.xml | 10 ++++++++++ manifest.xml | 10 ++++++++++ 4 files changed, 35 insertions(+) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 723b6b6e..f6804417 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -352,6 +352,16 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 +# NeuralNetworks +GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) +GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zebu/prebuilts/libs) +ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) +ARMNN_COMPUTE_CL_ENABLE := 1 +else +ARMNN_COMPUTE_CL_ENABLE := 0 +endif +ARMNN_COMPUTE_NEON_ENABLE := 1 + # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index b9dcf4cd..30e1ef9e 100644 --- a/device.mk +++ b/device.mk @@ -225,6 +225,8 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) +include device/google/gs101/neuralnetwork/neuralnetwork.mk + include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_todx_mali_csffw.bin \ @@ -998,6 +1000,9 @@ PRODUCT_COPY_FILES += \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.cfg:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.cfg \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.nprf:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.nprf \ +# ARM NN files +ARMNN_COMPUTE_CL_ENABLE := 1 + # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index 0427aa5e..dc91529d 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -82,6 +82,16 @@ default + + android.hardware.neuralnetworks + hwbinder + 1.3 + + IDevice + google-armnn + + @1.3::IDevice/google-armnn + android.hardware.neuralnetworks hwbinder diff --git a/manifest.xml b/manifest.xml index b6e6396b..90af32bd 100644 --- a/manifest.xml +++ b/manifest.xml @@ -13,6 +13,16 @@ hwbinder @1.2::IBootControl/default + + android.hardware.neuralnetworks + hwbinder + 1.3 + + IDevice + google-armnn + + @1.3::IDevice/google-armnn + com.google.input.algos.spd From 86e42129ab79a7158ad771e124f97b4e42b083e2 Mon Sep 17 00:00:00 2001 From: Renato Grottesi Date: Thu, 13 Jul 2023 08:40:59 +0000 Subject: [PATCH 14/74] Revert^2 "Remove settings for old ArmNN HIDL backend" a15331d5744dd7b5ca9a9ee3d9f356aff067631e Compile ArmNN shim over the support library. Remove settings for the old HIDL backend. The new ones will be in the gs-common folder. Test: Local run of CtsNNAPITestCases Test: Local run of VtsHalNeuralnetworksTargetTest Test: Local run of MLTS Benchmark Bug: 283724775 Change-Id: Ic9f1c26345e52df8b6ef75e2a8261d71a8950c72 --- BoardConfig-common.mk | 10 ---------- device.mk | 5 ----- manifest-gralloc3.xml | 10 ---------- manifest.xml | 10 ---------- 4 files changed, 35 deletions(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index f6804417..723b6b6e 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -352,16 +352,6 @@ BOARD_VNDK_VERSION := current # H/W align restriction of MM IPs BOARD_EXYNOS_S10B_FORMAT_ALIGN := 64 -# NeuralNetworks -GPU_SOURCE_PRESENT := $(wildcard vendor/arm/mali/valhall) -GPU_PREBUILD_PRESENT := $(wildcard vendor/google_devices/zebu/prebuilts/libs) -ifneq (,$(strip $(GPU_SOURCE_PRESENT) $(GPU_PREBUILD_PRESENT))) -ARMNN_COMPUTE_CL_ENABLE := 1 -else -ARMNN_COMPUTE_CL_ENABLE := 0 -endif -ARMNN_COMPUTE_NEON_ENABLE := 1 - # Boot.img BOARD_RAMDISK_USE_LZ4 := true #BOARD_KERNEL_BASE := 0x80000000 diff --git a/device.mk b/device.mk index 30e1ef9e..b9dcf4cd 100644 --- a/device.mk +++ b/device.mk @@ -225,8 +225,6 @@ PRODUCT_SOONG_NAMESPACES += \ $(call soong_config_set,pixel_mali,soc,$(TARGET_BOARD_PLATFORM)) -include device/google/gs101/neuralnetwork/neuralnetwork.mk - include device/google/gs-common/gpu/gpu.mk PRODUCT_PACKAGES += \ csffw_image_prebuilt__firmware_prebuilt_todx_mali_csffw.bin \ @@ -1000,9 +998,6 @@ PRODUCT_COPY_FILES += \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.cfg:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.cfg \ device/google/$(TARGET_BOARD_PLATFORM)/radio/config/Pixel_stability.nprf:$(TARGET_COPY_OUT_VENDOR)/etc/modem/Pixel_stability.nprf \ -# ARM NN files -ARMNN_COMPUTE_CL_ENABLE := 1 - # Vibrator Diag PRODUCT_PACKAGES_DEBUG += \ diag-vibrator \ diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index dc91529d..0427aa5e 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -82,16 +82,6 @@ default - - android.hardware.neuralnetworks - hwbinder - 1.3 - - IDevice - google-armnn - - @1.3::IDevice/google-armnn - android.hardware.neuralnetworks hwbinder diff --git a/manifest.xml b/manifest.xml index 90af32bd..b6e6396b 100644 --- a/manifest.xml +++ b/manifest.xml @@ -13,16 +13,6 @@ hwbinder @1.2::IBootControl/default - - android.hardware.neuralnetworks - hwbinder - 1.3 - - IDevice - google-armnn - - @1.3::IDevice/google-armnn - com.google.input.algos.spd From 671e69eef09f6b0bb9d8b537988c6b3baaa99749 Mon Sep 17 00:00:00 2001 From: Dinesh Yadav Date: Mon, 10 Jul 2023 05:48:36 +0000 Subject: [PATCH 15/74] [Cleanup] Move gxp sepolicies to gs-common for P22 Due to cleanup /gs-common/gxp/dump.mk has been changed to /gs-common/gxp/gxp.mk Bug: 288368306 Change-Id: I2b463a8e696644703b7cedcf73516ffa9459e9f9 Signed-off-by: Dinesh Yadav --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index b9dcf4cd..0017975a 100644 --- a/device.mk +++ b/device.mk @@ -26,7 +26,7 @@ include device/google/gs-common/pixel_metrics/pixel_metrics.mk include device/google/gs-common/performance/perf.mk include device/google/gs-common/display/dump.mk include device/google/gs-common/camera/dump.mk -include device/google/gs-common/gxp/dump.mk +include device/google/gs-common/gxp/gxp.mk include device/google/gs-common/gps/dump/log.mk include device/google/gs-common/radio/dump.mk include device/google/gs-common/umfw_stat/umfw_stat.mk From bcb959448c75667b725fb6d00510454575fd4c22 Mon Sep 17 00:00:00 2001 From: Devika Krishnadas Date: Thu, 22 Jun 2023 08:57:51 +0000 Subject: [PATCH 16/74] Use graphics allocator 2 Bug: 287353739 Test: atest VtsHalGraphicsMapperV4_0TargetTest Change-Id: I080045d75273fcf01d9129dee85fdf3c7b801117 Signed-off-by: Devika Krishnadas --- device.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/device.mk b/device.mk index 2f7ce852..bb325755 100644 --- a/device.mk +++ b/device.mk @@ -507,8 +507,7 @@ PRODUCT_PACKAGES += \ com.android.future.usb.accessory PRODUCT_PACKAGES += \ - android.hardware.graphics.mapper@4.0-impl \ - android.hardware.graphics.allocator-V1-service + android.hardware.graphics.allocator-V2-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From d2adab192e35bd21d2f7271420fc97bc9452802d Mon Sep 17 00:00:00 2001 From: Priyanka Advani Date: Mon, 24 Jul 2023 19:52:02 +0000 Subject: [PATCH 17/74] Revert "Use graphics allocator 2" Revert submission 23772493-allocator-aidl2 Reason for revert: Probable culprit for b/292565867, b/292569168 Reverted changes: /q/submissionid:23772493-allocator-aidl2 Change-Id: I265a338737dfd6bc03736cacf545cb426ab0b5e8 --- device.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/device.mk b/device.mk index bb325755..2f7ce852 100644 --- a/device.mk +++ b/device.mk @@ -507,7 +507,8 @@ PRODUCT_PACKAGES += \ com.android.future.usb.accessory PRODUCT_PACKAGES += \ - android.hardware.graphics.allocator-V2-service + android.hardware.graphics.mapper@4.0-impl \ + android.hardware.graphics.allocator-V1-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From 0606f21e3e204ff9b97a7132e5f2852daa0a0115 Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Fri, 21 Apr 2023 11:03:05 -0700 Subject: [PATCH 18/74] Fix swiftshader libs and properties Bug: 268269980 Test: Boots to home with SW and SELinux disabled Change-Id: Ib833e1f575ce3172e40e8975eefe57a4c23414c4 --- device.mk | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/device.mk b/device.mk index 2f7ce852..f6e14c20 100644 --- a/device.mk +++ b/device.mk @@ -218,7 +218,11 @@ USES_GAUDIO := true USE_SWIFTSHADER := false # HWUI -TARGET_USES_VULKAN = true +ifeq ($(USE_SWIFTSHADER),true) + TARGET_USES_VULKAN = false +else + TARGET_USES_VULKAN = true +endif PRODUCT_SOONG_NAMESPACES += \ vendor/arm/mali/valhall @@ -233,9 +237,6 @@ PRODUCT_PACKAGES += \ libOpenCL \ libgpudataproducer \ -PRODUCT_VENDOR_PROPERTIES += \ - ro.hardware.vulkan=mali - # Mali Configuration Properties # b/221255664 prevents setting PROTECTED_MAX_CORE_COUNT=2 PRODUCT_VENDOR_PROPERTIES += \ @@ -245,13 +246,6 @@ PRODUCT_VENDOR_PROPERTIES += \ vendor.mali.base_protected_tls_max=67108864 \ vendor.mali.platform_agt_frequency_khz=24576 -ifeq ($(USE_SWIFTSHADER),true) -PRODUCT_PACKAGES += \ - libGLESv1_CM_swiftshader \ - libEGL_swiftshader \ - libGLESv2_swiftshader -endif - PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \ frameworks/native/data/etc/android.hardware.vulkan.version-1_3.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \ @@ -260,12 +254,20 @@ PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.software.vulkan.deqp.level-2023-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.vulkan.deqp.level.xml \ frameworks/native/data/etc/android.software.opengles.deqp.level-2023-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml +ifeq ($(USE_SWIFTSHADER),true) +PRODUCT_PACKAGES += \ + vulkan.pastel +endif + ifeq ($(USE_SWIFTSHADER),true) PRODUCT_VENDOR_PROPERTIES += \ - ro.hardware.egl = swiftshader + ro.hardware.egl = mali \ + persist.graphics.egl = angle \ + ro.hardware.vulkan = pastel else PRODUCT_VENDOR_PROPERTIES += \ - ro.hardware.egl = mali + ro.hardware.egl = mali \ + ro.hardware.vulkan = mali endif # Configure EGL blobcache From 2c29945b4572f5888f1c35af7114b0011a480062 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Tue, 1 Aug 2023 23:05:27 +0000 Subject: [PATCH 19/74] Allow for the previous version of com.google.face.debug In the 'next' release configuration, we don't allow using unfrozen versions of interfaces, so the previous version is served instead. Once this interface is frozen, this previous version can be removed from the FCM. Test: lunch cheetah-next-userdebug && m Bug: 290265210 Bug: 294127698 Change-Id: If00ff4b1e4094dd3bfd9fd41a29074daf2f0304c --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 6e4cbd15..ddb2ba5a 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -42,7 +42,7 @@ com.google.face.debug - 4 + 3-4 IDebugHost default From b97e3d8cc4529f3ab32fb41e343319d3cd6efc5d Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Wed, 31 May 2023 00:11:19 +0000 Subject: [PATCH 20/74] Usb: Listen to USB sysfs attribute for device state Poll the sysfs attributes that represents usb device state in either of the following states: not attached, powered, default, addressed, configured. The information is useful in detecting non compliant USB cable, which will be supported in later patch sets. This patch lays the ground work to monitor the sysfs attributes in both device and host modes. The thread to poll uevent is re-used to poll sysfs because this serialize type-C port events and usb device state changes, hence prevent potential races. Added a thin abstration layer and a map to keep epoll data so that it's easier to dynamically add/delete files to epoll, which is needed for usb devices in host mode. Bug: 285199434 Test: trigger usb device state changes in device and host mode Change-Id: Ie5389d051deb28dbb486c2f27319b3cc9e89312f --- usb/usb/Usb.cpp | 190 +++++++++++++++++++++++++++++++++++++++++------- usb/usb/Usb.h | 23 ++++++ 2 files changed, 185 insertions(+), 28 deletions(-) diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index e4f0b354..6c564b7d 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -87,10 +87,15 @@ constexpr char kThermalZoneForTempReadSecondary2[] = "qi_therm"; constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_active"; constexpr char KPogoMoveDataToUsb[] = "/sys/devices/platform/google,pogo/move_data_to_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; +constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +// xhci-hcd-exynos and usb device numbering could vary on different platforms +constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; + constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); +#define USB_STATE_MAX_LEN 20 #define CTRL_TRANSFER_TIMEOUT_MSEC 1000 #define GL852G_VENDOR_ID 0x05e3 #define GL852G_PRODUCT_ID1 0x0608 @@ -990,17 +995,113 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -struct data { - int uevent_fd; - ::aidl::android::hardware::usb::Usb *usb; -}; +static void unregisterEpollEntry(Usb *usb, std::string name) { + std::map *map; + int fd; -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { + map = &usb->mEpollEntries; + auto it = map->find(name); + if (it != map->end()) { + ALOGI("epoll unregister %s", name.c_str()); + fd = it->second.payload.fd; + epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); + close(fd); + map->erase(it); + } +} + +static void unregisterEpollEntries(Usb *usb) { + std::map *map; + std::string name; + + map = &usb->mEpollEntries; + for (auto it = map->begin(); it != map->end();) { + name = it->first; + it++; + unregisterEpollEntry(usb, name); + } +} + +static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + std::map *map; + struct Usb::epollEntry *entry; + struct epoll_event ev; + + map = &usb->mEpollEntries; + if (map->find(name) != map->end()) { + ALOGE("%s already registered", name.c_str()); + unregisterEpollEntry(usb, name); + } + + entry = &(*map)[name]; + entry->payload.fd = fd; + entry->payload.name = name; + entry->payload.usb = usb; + entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); + + ev.events = flags; + ev.data.ptr = (void *)&entry->cb; + + if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + unregisterEpollEntry(usb, name); + return -1; + } + + ALOGI("epoll register %s", name.c_str()); + + return 0; +} + +static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + int fd; + + fd = open(name.c_str(), O_RDONLY); + if (fd < 0) { + ALOGE("Cannot open %s", name.c_str()); + return -1; + } + + return registerEpollEntry(usb, name, fd, flags, func); +} + +static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { + device->latestState.clear(); + device->portResetCount = 0; +} + +static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { + ALOGI("Update USB device state: %s", state); + + device->latestState = state; + + if (!std::strcmp(state, "configured\n")) { + device->portResetCount = 0; + } else if (!std::strcmp(state, "default\n")) { + device->portResetCount++; + } +} + +static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + struct Usb::usbDeviceState *device; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); +} + +static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; + std::cmatch match; - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1046,6 +1147,29 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } else if (!strncmp(cp, kOverheatStatsDev, strlen(kOverheatStatsDev))) { ALOGV("Overheat Cooling device suez update"); report_overheat_event(payload->usb); + } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { + /* + * Matched strings: + * 1st: entire string + * 2nd: uevent action, either "bind" or "unbind" + * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto + * 4th: usb device number, e.g. 1 for usb1 + * + * The strings are used to composed usb device state path, e.g. + * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state + */ + if (match.size() == 4) { + std::string action = match[1].str(); + std::string id = match[3].str(); + std::string path = "/sys" + match[2].str() + "usb" + id + "/" + + id + "-0:1.0/usb" + id + "-port1/state"; + if (action == "bind") { + registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); + } else if (action == "unbind") { + unregisterEpollEntry(payload->usb, path); + clearUsbDeviceState(&payload->usb->mHostStateMap[path]); + } + } } /* advance to after the next \0 */ while (*cp++) { @@ -1053,37 +1177,46 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } } +static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mDeviceState, state); +} + void *work(void *param) { int epoll_fd, uevent_fd; - struct epoll_event ev; int nevents = 0; - struct data payload; + Usb *usb = (Usb *)param; ALOGE("creating thread"); - uevent_fd = uevent_open_socket(64 * 1024, true); - - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (::aidl::android::hardware::usb::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); + return NULL; + } + usb->mEpollFd = epoll_fd; + + // Monitor uevent + uevent_fd = uevent_open_socket(64 * 1024, true); + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed"); + goto error; + } + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { + ALOGE("failed to monitor uevent"); goto error; } - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); + // Monitor udc state + if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { + ALOGE("failed to monitor udc state"); goto error; } @@ -1100,14 +1233,15 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, - &payload); + (*(std::function*)events[n].data.ptr)(events[n].events); } } ALOGI("exiting worker thread"); error: - close(uevent_fd); + unregisterEpollEntries(usb); + + usb->mEpollFd = -1; if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index e45a5ed0..faaa270e 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -96,6 +96,29 @@ struct Usb : public BnUsb { // Usb hub vendor command settings for JK level tuning int mUsbHubVendorCmdValue; int mUsbHubVendorCmdIndex; + + // USB device state monitoring + struct usbDeviceState { + std::string latestState; + int portResetCount; + }; + struct usbDeviceState mDeviceState; + // Map host device path name to usbDeviceState + std::map mHostStateMap; + + // File monitoring through epoll + int mEpollFd; + struct payload { + int fd; + std::string name; + Usb *usb; + }; + struct epollEntry { + struct payload payload; + std::function cb; + }; + std::map mEpollEntries; + private: pthread_t mPoll; pthread_t mUsbHost; From 94e5bab69e1ac2da93d9df2eb26f02199d4a0e48 Mon Sep 17 00:00:00 2001 From: Mark Chang Date: Wed, 26 Jul 2023 06:00:40 +0000 Subject: [PATCH 21/74] Remove IScreenProtectorDetectorService. Serivce not enabled on gs201 devices. Test: Failed tests no longer reported. Bug: 293172250 Change-Id: Iaaa21060c7c33d4e013d3d7c85065562a3f0c1ad Signed-off-by: Mark Chang --- device_framework_matrix_product.xml | 7 ------- manifest-gralloc3.xml | 7 ------- manifest.xml | 7 ------- 3 files changed, 21 deletions(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index ddb2ba5a..488ec649 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -76,13 +76,6 @@ default - - com.google.input.algos.spd - - IScreenProtectorDetectorService - default - - com.google.input 2 diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index 0427aa5e..fee04558 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -87,13 +87,6 @@ hwbinder @1.3::IDevice/google-edgetpu - - com.google.input.algos.spd - - IScreenProtectorDetectorService - default - - com.google.input 2 diff --git a/manifest.xml b/manifest.xml index b6e6396b..031b46f3 100644 --- a/manifest.xml +++ b/manifest.xml @@ -13,13 +13,6 @@ hwbinder @1.2::IBootControl/default - - com.google.input.algos.spd - - IScreenProtectorDetectorService - default - - com.google.input 2 From e9dab393fc378866f49f5533698e6e9b367ef3c2 Mon Sep 17 00:00:00 2001 From: Ziyi Cui Date: Thu, 11 May 2023 04:05:14 +0000 Subject: [PATCH 22/74] gs201: Add path reading for StormIRQ Bug: 279486693 Test: Verified the existence of atom and correctness of atom stats adb shell cmd stats print-logs && logcat -b all | grep -i 105043 Change-Id: Iae8f8de862c21e2b8e6b32618bc5971cbe98b1ca Signed-off-by: Ziyi Cui --- pixelstats/pixelstats-vendor.gs201.rc | 3 ++- pixelstats/service.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pixelstats/pixelstats-vendor.gs201.rc b/pixelstats/pixelstats-vendor.gs201.rc index d324b6a8..70d875ea 100644 --- a/pixelstats/pixelstats-vendor.gs201.rc +++ b/pixelstats/pixelstats-vendor.gs201.rc @@ -1,6 +1,7 @@ on property:sys.boot_completed=1 start vendor.pixelstats_vendor - +on post-fs-data + chown system system /sys/kernel/metrics/irq/stats_reset service vendor.pixelstats_vendor /vendor/bin/pixelstats-vendor class hal user system diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index d9f65e93..b7df808e 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -80,6 +80,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { }, .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics", .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics", + .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics", + .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset", .ModemPcieLinkStatsPath = "/sys/devices/platform/11920000.pcie/link_stats", .WifiPcieLinkStatsPath = "/sys/devices/platform/14520000.pcie/link_stats" }; From ee799342d39bb17ec558a371df536e1e2c74c800 Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Fri, 28 Jul 2023 15:53:57 -0700 Subject: [PATCH 23/74] gs201: update the thermal dump script path Update the thermal dump script path. Bug: 289146743 Test: Compilation test. Change-Id: Ibc12584784d4e7d4b99725efe943ccb71a1684ac Signed-off-by: Ram Chandrasekar --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 625e236e..b4958083 100644 --- a/device.mk +++ b/device.mk @@ -21,7 +21,7 @@ include device/google/gs-common/soc/soc.mk include device/google/gs-common/soc/freq.mk include device/google/gs-common/modem/modem.mk include device/google/gs-common/aoc/aoc.mk -include device/google/gs-common/thermal/thermal.mk +include device/google/gs-common/thermal/dump/thermal.mk include device/google/gs-common/pixel_metrics/pixel_metrics.mk include device/google/gs-common/performance/perf.mk include device/google/gs-common/display/dump.mk From cae50eee5f0617ac17944e9866e31f2019e4bcc3 Mon Sep 17 00:00:00 2001 From: Ram Chandrasekar Date: Fri, 28 Jul 2023 16:06:01 -0700 Subject: [PATCH 24/74] gs201: update thermal HAL makefile path Update thermal makefile path to the new common folder. Bug: 289146743 Test: Compilation test Change-Id: I80e5e74fcaf0dbb98661db1619feb72e8ff2c04c Signed-off-by: Ram Chandrasekar --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index b4958083..dfc9d194 100644 --- a/device.mk +++ b/device.mk @@ -22,6 +22,7 @@ include device/google/gs-common/soc/freq.mk include device/google/gs-common/modem/modem.mk include device/google/gs-common/aoc/aoc.mk include device/google/gs-common/thermal/dump/thermal.mk +include device/google/gs-common/thermal/thermal_hal/device.mk include device/google/gs-common/pixel_metrics/pixel_metrics.mk include device/google/gs-common/performance/perf.mk include device/google/gs-common/display/dump.mk @@ -1073,7 +1074,6 @@ include device/google/gs101/telephony/pktrouter.mk # Thermal HAL PRODUCT_PROPERTY_OVERRIDES += persist.vendor.enable.thermal.genl=true -include hardware/google/pixel/thermal/device.mk # EdgeTPU include device/google/gs-common/edgetpu/edgetpu.mk From a1858d2df89353ea9c11ace166b3512fd7e44411 Mon Sep 17 00:00:00 2001 From: kierancyphus Date: Thu, 11 May 2023 21:40:10 +0800 Subject: [PATCH 25/74] Create liboemservice proxy HAL declaration Test: Manually flash device Bug: 263307589 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:4eee06da1f8cbb02e0ce6d6bd21df0a443ecbac3) Merged-In: I78c62e807bc8d624b6940847debd4fb1dcd0a153 Change-Id: I78c62e807bc8d624b6940847debd4fb1dcd0a153 --- device_framework_matrix_product.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 488ec649..d4beefb6 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -134,6 +134,13 @@ sced0 + + com.google.pixel.modem.logmasklibrary + + ILiboemserviceProxy + default + + vendor.samsung_slsi.telephony.hardware.radioExternal 1.1 From 28b5e85a64748083cda177a652418c777de9b075 Mon Sep 17 00:00:00 2001 From: Hsin-Yi Chen Date: Fri, 18 Aug 2023 07:41:37 +0000 Subject: [PATCH 26/74] Revert "Create liboemservice proxy HAL declaration" This reverts commit a1858d2df89353ea9c11ace166b3512fd7e44411. Bug: 296329753 Reason for revert: broken build Change-Id: I03570724fabcd26eff9e27220d3fc27ab70f6960 --- device_framework_matrix_product.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index d4beefb6..488ec649 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -134,13 +134,6 @@ sced0 - - com.google.pixel.modem.logmasklibrary - - ILiboemserviceProxy - default - - vendor.samsung_slsi.telephony.hardware.radioExternal 1.1 From a4def4a5593b94289ab707189e941fe83f56f6b8 Mon Sep 17 00:00:00 2001 From: Jigar Thakkar Date: Mon, 14 Aug 2023 14:37:43 +0000 Subject: [PATCH 27/74] Stop pre-install of apps on private profile This change adds do-not-install tags on internal apps that we do not want to preinstall on the private profile. Bug: 289017904 Test: Tested manually on device Change-Id: I0c5faea3eac31881663e893951bea20648a6baa1 --- preinstalled-packages-product-gs201-device-debug.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/preinstalled-packages-product-gs201-device-debug.xml b/preinstalled-packages-product-gs201-device-debug.xml index a0b67c36..58eb9dbc 100644 --- a/preinstalled-packages-product-gs201-device-debug.xml +++ b/preinstalled-packages-product-gs201-device-debug.xml @@ -22,6 +22,7 @@ + false - + + + + + com.google.android.youtube:0.07 + com.spotify.music:0.05 + com.reddit.frontpage:0.07 + com.zhiliaoapp.musically:0.07 + com.bilibili.app.in:0.07 + com.twitter.android:0.07 + + From 26abdf4ee288c9fabdef59e524202c2fa9148501 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Thu, 5 Oct 2023 21:08:39 +0000 Subject: [PATCH 40/74] Usb: capture and upload Suez metric VendorUsbDataSessionEvent Upload metrics for the last data session that just ends upon data role changes. The change is purely metric collection and does not change any business logic. This is a direct CP from ag/24816727 Bug: 297224564 Test: Trigger metric upload for both host and device mode and verify it by statsd_testdrive Change-Id: I823ae8712b7914cfc7f6c6379acb3749d13c0974 (cherry picked from commit ccb35c81ff0bbfb013136bae7a572280b196bd1a) --- usb/usb/Android.bp | 1 + usb/usb/Usb.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++-- usb/usb/Usb.h | 11 +++++- 3 files changed, 101 insertions(+), 4 deletions(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index c35666aa..e28667fc 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -53,6 +53,7 @@ cc_binary { "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", "libbinder_ndk", + "libprotobuf-cpp-lite", ], static_libs: [ "libpixelusb-aidl", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index bae54638..9aa09da0 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -43,6 +43,7 @@ #include "Usb.h" #include +#include #include #include @@ -53,6 +54,9 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; using android::String8; using android::Vector; @@ -94,6 +98,8 @@ constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\ constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus); #define USB_STATE_MAX_LEN 20 #define CTRL_TRANSFER_TIMEOUT_MSEC 1000 @@ -909,6 +915,7 @@ void queryVersionHelper(android::hardware::usb::Usb *usb, queryMoistureDetectionStatus(currentPortStatus); queryPowerTransferStatus(currentPortStatus); queryNonCompliantChargerStatus(currentPortStatus); + queryUsbDataSession(usb, currentPortStatus); if (usb->mCallback != NULL) { ScopedAStatus ret = usb->mCallback->notifyPortStatusChange(*currentPortStatus, status); @@ -995,6 +1002,54 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } +void report_usb_data_session_event(android::hardware::usb::Usb *usb) { + std::vector events; + + if (usb->mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &usb->mDeviceState.states, + &usb->mDeviceState.timestamps, &event); + events.push_back(event); + } else if (usb->mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto &entry : usb->mHostStateMap) { + // Host port will at least get an not_attached event after enablement, + // skip upload if no additional state is added. + if (entry.second.states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &entry.second.states, + &entry.second.timestamps, &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty && usb->mHostStateMap.size() > 0) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, + &usb->mHostStateMap.begin()->second.states, + &usb->mHostStateMap.begin()->second.timestamps, + &event); + events.push_back(event); + } + } else { + return; + } + + const shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + static void unregisterEpollEntry(Usb *usb, std::string name) { std::map *map; int fd; @@ -1068,14 +1123,16 @@ static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, } static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->latestState.clear(); + device->states.clear(); + device->timestamps.clear(); device->portResetCount = 0; } static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { ALOGI("Update USB device state: %s", state); - device->latestState = state; + device->states.push_back(state); + device->timestamps.push_back(std::chrono::steady_clock::now()); if (!std::strcmp(state, "configured\n")) { device->portResetCount = 0; @@ -1095,6 +1152,37 @@ static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; + PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; + + if (newDataRole != usb->mDataRole) { + // Upload metrics for the last non-powerbrick data session that has ended + if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { + report_usb_data_session_event(usb); + } + + // Set up for the new data session + usb->mDataRole = newDataRole; + usb->mDataSessionStart = std::chrono::steady_clock::now(); + usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); + if (newDataRole == PortDataRole::DEVICE) { + clearUsbDeviceState(&usb->mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + for (auto &entry : usb->mHostStateMap) { + clearUsbDeviceState(&entry.second); + } + } + } + + // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data + // session when BC1.2 SDP times out and falls back to DCP + if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { + usb->mIsPowerBrickConnected = true; + } +} + static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; @@ -1167,7 +1255,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); } else if (action == "unbind") { unregisterEpollEntry(payload->usb, path); - clearUsbDeviceState(&payload->usb->mHostStateMap[path]); } } } diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index faaa270e..83bae889 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -99,12 +100,20 @@ struct Usb : public BnUsb { // USB device state monitoring struct usbDeviceState { - std::string latestState; + // Usb device state raw strings read from sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; int portResetCount; }; struct usbDeviceState mDeviceState; // Map host device path name to usbDeviceState std::map mHostStateMap; + // Cache relevant info for USB data session metrics collection when a session starts, including + // the data role, power brick status and the time when the session starts. + PortDataRole mDataRole; + bool mIsPowerBrickConnected; + std::chrono::steady_clock::time_point mDataSessionStart; // File monitoring through epoll int mEpollFd; From 66608337b72680f643d13d5c07d5084672db0c3f Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Wed, 11 Oct 2023 20:44:43 -0700 Subject: [PATCH 41/74] gs201: change swap_free_low_percentage to 10 Since LMKD introduced aggressive kill for cached apps, we can change the swap_free_low_percentage back to 10. Bug: 300660611 Change-Id: I0a37a3bb9470884c0522bc471704031ccaba4247 Signed-off-by: Minchan Kim --- device.mk | 4 ---- 1 file changed, 4 deletions(-) diff --git a/device.mk b/device.mk index cb0c4c4d..9172ff0c 100644 --- a/device.mk +++ b/device.mk @@ -1163,10 +1163,6 @@ PRODUCT_COPY_FILES += \ # Call deleteAllKeys if vold detects a factory reset PRODUCT_VENDOR_PROPERTIES += ro.crypto.metadata_init_delete_all_keys.enabled?=true -# Increase lmkd aggressiveness -PRODUCT_PROPERTY_OVERRIDES += \ - ro.lmk.swap_free_low_percentage=100 - # Hardware Info include hardware/google/pixel/HardwareInfo/HardwareInfo.mk From 7b8a5314695a3684c6947365ad2f5341db56007f Mon Sep 17 00:00:00 2001 From: guibing Date: Tue, 1 Aug 2023 21:07:19 +0000 Subject: [PATCH 42/74] init: gs201: update vendor_sched procfs paths Vendor sched procfs path hierarchy gets updated in kernel. Update the paths in init rc file and task profiles to match the change. Bug: 289151587 Test: pts-tradefed run commandAndExit pts -m PtsPerfWbsTestCases -t com.google.android.perfwbs.pts.SchedulerTest Change-Id: I94f17627f913e20323f9fe111a34fcc666f38a72 --- conf/init.gs201.rc | 154 ++++++++++++++++++++++----------------------- task_profiles.json | 52 +++++++-------- 2 files changed, 103 insertions(+), 103 deletions(-) diff --git a/conf/init.gs201.rc b/conf/init.gs201.rc index 9f83fef6..ae03ce9a 100644 --- a/conf/init.gs201.rc +++ b/conf/init.gs201.rc @@ -27,30 +27,30 @@ on init write /dev/sys/fs/by-name/userdata/data_io_flag 56 write /dev/sys/fs/by-name/userdata/node_io_flag 56 - chown system system /proc/vendor_sched/set_task_group_bg - chown system system /proc/vendor_sched/set_task_group_cam - chown system system /proc/vendor_sched/set_task_group_fg - chown system system /proc/vendor_sched/set_task_group_nnapi - chown system system /proc/vendor_sched/set_task_group_sys - chown system system /proc/vendor_sched/set_task_group_sysbg - chown system system /proc/vendor_sched/set_task_group_ta - chown system system /proc/vendor_sched/set_task_group_rt - chown system system /proc/vendor_sched/set_task_group_sf - chown system system /proc/vendor_sched/set_task_group_dex2oat - chown system system /proc/vendor_sched/set_task_group_cam_power - chown system system /proc/vendor_sched/set_task_group_ota - chown system system /proc/vendor_sched/set_proc_group_bg - chown system system /proc/vendor_sched/set_proc_group_cam - chown system system /proc/vendor_sched/set_proc_group_fg - chown system system /proc/vendor_sched/set_proc_group_nnapi - chown system system /proc/vendor_sched/set_proc_group_sys - chown system system /proc/vendor_sched/set_proc_group_sysbg - chown system system /proc/vendor_sched/set_proc_group_ta - chown system system /proc/vendor_sched/set_proc_group_rt - chown system system /proc/vendor_sched/set_proc_group_sf - chown system system /proc/vendor_sched/set_proc_group_dex2oat - chown system system /proc/vendor_sched/set_proc_group_cam_power - chown system system /proc/vendor_sched/set_proc_group_ota + chown system system /proc/vendor_sched/groups/bg/set_task_group + chown system system /proc/vendor_sched/groups/cam/set_task_group + chown system system /proc/vendor_sched/groups/fg/set_task_group + chown system system /proc/vendor_sched/groups/nnapi/set_task_group + chown system system /proc/vendor_sched/groups/sys/set_task_group + chown system system /proc/vendor_sched/groups/sys_bg/set_task_group + chown system system /proc/vendor_sched/groups/ta/set_task_group + chown system system /proc/vendor_sched/groups/rt/set_task_group + chown system system /proc/vendor_sched/groups/sf/set_task_group + chown system system /proc/vendor_sched/groups/dex2oat/set_task_group + chown system system /proc/vendor_sched/groups/cam_power/set_task_group + chown system system /proc/vendor_sched/groups/ota/set_task_group + chown system system /proc/vendor_sched/groups/bg/set_proc_group + chown system system /proc/vendor_sched/groups/cam/set_proc_group + chown system system /proc/vendor_sched/groups/fg/set_proc_group + chown system system /proc/vendor_sched/groups/nnapi/set_proc_group + chown system system /proc/vendor_sched/groups/sys/set_proc_group + chown system system /proc/vendor_sched/groups/sys_bg/set_proc_group + chown system system /proc/vendor_sched/groups/ta/set_proc_group + chown system system /proc/vendor_sched/groups/rt/set_proc_group + chown system system /proc/vendor_sched/groups/sf/set_proc_group + chown system system /proc/vendor_sched/groups/dex2oat/set_proc_group + chown system system /proc/vendor_sched/groups/cam_power/set_proc_group + chown system system /proc/vendor_sched/groups/ota/set_proc_group chown system system /proc/vendor_sched/prefer_idle_set chown system system /proc/vendor_sched/prefer_idle_clear chown system system /proc/vendor_sched/pmu_poll_enable @@ -76,30 +76,30 @@ on init chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu6_memlat@17000010/memlat_cpuidle_state_aware chown system system /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu7_memlat@17000010/memlat_cpuidle_state_aware - chmod 0220 /proc/vendor_sched/set_task_group_bg - chmod 0220 /proc/vendor_sched/set_task_group_cam - chmod 0220 /proc/vendor_sched/set_task_group_fg - chmod 0220 /proc/vendor_sched/set_task_group_nnapi - chmod 0220 /proc/vendor_sched/set_task_group_sys - chmod 0220 /proc/vendor_sched/set_task_group_sysbg - chmod 0220 /proc/vendor_sched/set_task_group_ta - chmod 0220 /proc/vendor_sched/set_task_group_rt - chmod 0220 /proc/vendor_sched/set_task_group_sf - chmod 0220 /proc/vendor_sched/set_task_group_dex2oat - chmod 0220 /proc/vendor_sched/set_task_group_cam_power - chmod 0220 /proc/vendor_sched/set_task_group_ota - chmod 0220 /proc/vendor_sched/set_proc_group_bg - chmod 0220 /proc/vendor_sched/set_proc_group_cam - chmod 0220 /proc/vendor_sched/set_proc_group_fg - chmod 0220 /proc/vendor_sched/set_proc_group_nnapi - chmod 0220 /proc/vendor_sched/set_proc_group_sys - chmod 0220 /proc/vendor_sched/set_proc_group_sysbg - chmod 0220 /proc/vendor_sched/set_proc_group_ta - chmod 0220 /proc/vendor_sched/set_proc_group_rt - chmod 0220 /proc/vendor_sched/set_proc_group_sf - chmod 0220 /proc/vendor_sched/set_proc_group_dex2oat - chmod 0220 /proc/vendor_sched/set_proc_group_cam_power - chmod 0220 /proc/vendor_sched/set_proc_group_ota + chmod 0220 /proc/vendor_sched/groups/bg/set_task_group + chmod 0220 /proc/vendor_sched/groups/cam/set_task_group + chmod 0220 /proc/vendor_sched/groups/fg/set_task_group + chmod 0220 /proc/vendor_sched/groups/nnapi/set_task_group + chmod 0220 /proc/vendor_sched/groups/sys/set_task_group + chmod 0220 /proc/vendor_sched/groups/sys_bg/set_task_group + chmod 0220 /proc/vendor_sched/groups/ta/set_task_group + chmod 0220 /proc/vendor_sched/groups/rt/set_task_group + chmod 0220 /proc/vendor_sched/groups/sf/set_task_group + chmod 0220 /proc/vendor_sched/groups/dex2oat/set_task_group + chmod 0220 /proc/vendor_sched/groups/cam_power/set_task_group + chmod 0220 /proc/vendor_sched/groups/ota/set_task_group + chmod 0220 /proc/vendor_sched/groups/bg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/cam/set_proc_group + chmod 0220 /proc/vendor_sched/groups/fg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/nnapi/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sys/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sys_bg/set_proc_group + chmod 0220 /proc/vendor_sched/groups/ta/set_proc_group + chmod 0220 /proc/vendor_sched/groups/rt/set_proc_group + chmod 0220 /proc/vendor_sched/groups/sf/set_proc_group + chmod 0220 /proc/vendor_sched/groups/dex2oat/set_proc_group + chmod 0220 /proc/vendor_sched/groups/cam_power/set_proc_group + chmod 0220 /proc/vendor_sched/groups/ota/set_proc_group chmod 0220 /proc/vendor_sched/prefer_idle_set chmod 0220 /proc/vendor_sched/prefer_idle_clear chmod 0220 /proc/vendor_sched/pmu_poll_enable @@ -165,12 +165,12 @@ on init mkdir /dev/socket/pdx/system/vr/sensors 0775 system system # Boot time 183626384 - write /proc/vendor_sched/ta_uclamp_min 159 - write /proc/vendor_sched/ta_prefer_idle 1 - write /proc/vendor_sched/fg_uclamp_min 159 - write /proc/vendor_sched/fg_prefer_idle 1 - write /proc/vendor_sched/sys_uclamp_min 159 - write /proc/vendor_sched/sys_prefer_idle 1 + write /proc/vendor_sched/groups/ta/uclamp_min 159 + write /proc/vendor_sched/groups/ta/prefer_idle 1 + write /proc/vendor_sched/groups/fg/uclamp_min 159 + write /proc/vendor_sched/groups/fg/prefer_idle 1 + write /proc/vendor_sched/groups/sys/uclamp_min 159 + write /proc/vendor_sched/groups/sys/prefer_idle 1 # governor setting write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor sched_pixel @@ -221,8 +221,8 @@ on init chown system system /dev/cpuset/camera-daemon-mid-high-group/tasks chmod 0664 /dev/cpuset/camera-daemon-mid-high-group/tasks - write /proc/vendor_sched/cam_prefer_idle 1 - write /proc/vendor_sched/cam_uclamp_min 1 + write /proc/vendor_sched/groups/cam/prefer_idle 1 + write /proc/vendor_sched/groups/cam/uclamp_min 1 chown system system /dev/cpuset/cgroup.procs @@ -324,8 +324,8 @@ on init chown system system /dev/bbd_pwrstat # Add a boost for NNAPI HAL - write /proc/vendor_sched/nnapi_prefer_idle 0 - write /proc/vendor_sched/nnapi_uclamp_min 512 + write /proc/vendor_sched/groups/nnapi/prefer_idle 0 + write /proc/vendor_sched/groups/nnapi/uclamp_min 512 # Add memlat governor settings write /sys/class/devfreq/gs_memlat_devfreq:devfreq_mif_cpu0_memlat@17000010/polling_interval 10 @@ -420,7 +420,7 @@ on post-fs-data on zygote-start # For PixelLogger configuration file. chmod 0771 /data/vendor/wifi - write /proc/vendor_sched/sys_uclamp_min 0 + write /proc/vendor_sched/groups/sys/uclamp_min 0 on post-fs-data # Create the directories used by the Wireless subsystem @@ -730,25 +730,25 @@ on property:sys.boot_completed=1 setprop vendor.powerhal.init 1 # Setup final cpu.uclamp - write /proc/vendor_sched/ta_uclamp_min 1 - write /proc/vendor_sched/fg_uclamp_min 0 - write /proc/vendor_sched/sys_prefer_idle 0 + write /proc/vendor_sched/groups/ta/uclamp_min 1 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/sys/prefer_idle 0 # Set ug group - write /proc/vendor_sched/bg_ug 0 - write /proc/vendor_sched/sysbg_ug 0 - write /proc/vendor_sched/ota_ug 0 - write /proc/vendor_sched/dex2oat_ug 1 - write /proc/vendor_sched/ta_ug 1 + write /proc/vendor_sched/groups/bg/ug 0 + write /proc/vendor_sched/groups/sys_bg/ug 0 + write /proc/vendor_sched/groups/ota/ug 0 + write /proc/vendor_sched/groups/dex2oat/ug 1 + write /proc/vendor_sched/groups/ta/ug 1 # Set bg group throttle write /proc/vendor_sched/ug_bg_group_throttle ${persist.device_config.vendor_system_native.ug_bg_group_throttle:-308} # Set uclamp.max for some groups, which could indicate cpu importance used in scheduling - write /proc/vendor_sched/bg_uclamp_max 512 - write /proc/vendor_sched/sysbg_uclamp_max 512 - write /proc/vendor_sched/ota_uclamp_max 512 - write /proc/vendor_sched/dex2oat_uclamp_max 615 + write /proc/vendor_sched/groups/bg/uclamp_max 512 + write /proc/vendor_sched/groups/sys_bg/uclamp_max 512 + write /proc/vendor_sched/groups/ota/uclamp_max 512 + write /proc/vendor_sched/groups/dex2oat/uclamp_max 615 # Set PMU freq limit parameters write /sys/devices/system/cpu/cpufreq/policy0/sched_pixel/lcpi_threshold 2 @@ -1038,12 +1038,12 @@ on charger # Cancel boot devfreq and uclamp write /sys/devices/platform/17000010.devfreq_mif/devfreq/17000010.devfreq_mif/exynos_data/cancel_boot_freq 1 write /sys/devices/platform/17000020.devfreq_int/devfreq/17000020.devfreq_int/exynos_data/cancel_boot_freq 1 - write /proc/vendor_sched/ta_uclamp_min 0 - write /proc/vendor_sched/ta_prefer_idle 0 - write /proc/vendor_sched/fg_uclamp_min 0 - write /proc/vendor_sched/fg_prefer_idle 0 - write /proc/vendor_sched/sys_uclamp_min 0 - write /proc/vendor_sched/sys_prefer_idle 0 + write /proc/vendor_sched/groups/ta/uclamp_min 0 + write /proc/vendor_sched/groups/ta/prefer_idle 0 + write /proc/vendor_sched/groups/fg/uclamp_min 0 + write /proc/vendor_sched/groups/fg/prefer_idle 0 + write /proc/vendor_sched/groups/sys/uclamp_min 0 + write /proc/vendor_sched/groups/sys/prefer_idle 0 # Enable SICD write /sys/devices/system/cpu/cpupm/cpupm/sicd 1 diff --git a/task_profiles.json b/task_profiles.json index 961857de..fda6c3ea 100644 --- a/task_profiles.json +++ b/task_profiles.json @@ -7,8 +7,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ta", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ta", + "FilePath": "/proc/vendor_sched/groups/ta/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ta/set_proc_group", "Value": "", "LogFailures": "false" } @@ -22,8 +22,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_cam", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_cam", + "FilePath": "/proc/vendor_sched/groups/cam/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/cam/set_proc_group", "Value": "", "LogFailures": "false" } @@ -37,8 +37,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_cam_power", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_cam_power", + "FilePath": "/proc/vendor_sched/groups/cam_power/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/cam_power/set_proc_group", "Value": "", "LogFailures": "false" } @@ -52,8 +52,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_dex2oat", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_dex2oat", + "FilePath": "/proc/vendor_sched/groups/dex2oat/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/dex2oat/set_proc_group", "Value": "", "LogFailures": "false" } @@ -67,8 +67,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ota", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ota", + "FilePath": "/proc/vendor_sched/groups/ota/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ota/set_proc_group", "Value": "", "LogFailures": "false" } @@ -121,8 +121,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_bg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_bg", + "FilePath": "/proc/vendor_sched/groups/bg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/bg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -136,8 +136,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sys", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sys", + "FilePath": "/proc/vendor_sched/groups/sys/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sys/set_proc_group", "Value": "", "LogFailures": "false" } @@ -151,8 +151,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_fg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_fg", + "FilePath": "/proc/vendor_sched/groups/fg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/fg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -166,8 +166,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_ta", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_ta", + "FilePath": "/proc/vendor_sched/groups/ta/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/ta/set_proc_group", "Value": "", "LogFailures": "false" } @@ -181,8 +181,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_nnapi", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_nnapi", + "FilePath": "/proc/vendor_sched/groups/nnapi/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/nnapi/set_proc_group", "Value": "", "LogFailures": "false" } @@ -196,8 +196,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sysbg", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sysbg", + "FilePath": "/proc/vendor_sched/groups/sys_bg/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sys_bg/set_proc_group", "Value": "", "LogFailures": "false" } @@ -219,8 +219,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_sf", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_sf", + "FilePath": "/proc/vendor_sched/groups/sf/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/sf/set_proc_group", "Value": "", "LogFailures": "false" } @@ -242,8 +242,8 @@ "Name": "WriteFile", "Params": { - "FilePath": "/proc/vendor_sched/set_task_group_rt", - "ProcFilePath": "/proc/vendor_sched/set_proc_group_rt", + "FilePath": "/proc/vendor_sched/groups/rt/set_task_group", + "ProcFilePath": "/proc/vendor_sched/groups/rt/set_proc_group", "Value": "", "LogFailures": "false" } From cc794e617ca40172a3585655e2b8b6ed8e0c38bf Mon Sep 17 00:00:00 2001 From: Jasmine Cha Date: Tue, 17 Oct 2023 15:12:10 +0800 Subject: [PATCH 43/74] audio: fix typo Bug: 305838207 Test: build pass/ recording runtime tuning Change-Id: I1d0bb63910b2b3e249809e89ff1408f28976855b Signed-off-by: Jasmine Cha --- BoardConfig-common.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BoardConfig-common.mk b/BoardConfig-common.mk index 723b6b6e..e1d6cd4f 100644 --- a/BoardConfig-common.mk +++ b/BoardConfig-common.mk @@ -233,7 +233,7 @@ $(call soong_config_set,aoc_audio_func,ext_hidl,true) ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) $(call soong_config_set,aoc_audio_func,dump_usecase_data,true) $(call soong_config_set,aoc_audio_func,hal_socket_control,true) -$(call soong_config_set,aoc_audio_func,record_tunning_keys,true) +$(call soong_config_set,aoc_audio_func,record_tuning_keys,true) endif ifneq (,$(filter aosp_%,$(TARGET_PRODUCT))) From 131a635fe99b79a409b168d77f7cfeec441a7e51 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Oct 2023 15:15:21 +0000 Subject: [PATCH 44/74] Enable HDR shader priming in SurfaceFlinger Bug: 295257834 Test: manual - check that HDR shaders are generated after applying Change-Id: Icf67e64500aa8982dae0cf4a5540389da62cbf26 --- device.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/device.mk b/device.mk index 9172ff0c..e9ca7a99 100644 --- a/device.mk +++ b/device.mk @@ -282,6 +282,9 @@ PRODUCT_VENDOR_PROPERTIES += \ graphics.gpu.profiler.support=true \ debug.renderengine.backend=skiaglthreaded +# b/295257834 Add HDR shaders to SurfaceFlinger's pre-warming cache +PRODUCT_VENDOR_PROPERTIES += ro.surface_flinger.prime_shader_cache.ultrahdr=1 + # GRAPHICS - GPU (end) # #################### From c13cd03ccf360755bcebaa0df94427a3ac81217e Mon Sep 17 00:00:00 2001 From: Will McVicker Date: Tue, 17 Oct 2023 09:31:59 -0700 Subject: [PATCH 45/74] fstab: allow unlocked devices to boot with AVB test key Set `avb_keys=/avb` for dynamic kernel partitions to allow booting unlocked devices with a custom kernel that is signed using a test key. This allows a few things: 1) Dogfooders can flash a custom kernel without wiping their device. This can help developers track down hard-to-reproduce bugs without rolling out a patch to the whole dogfooder population. 2) Developers can uprev their device's kernel without wiping their device or packaging the kernel with an Android platform build. Test: flash production userdebug build, then flash custom kernel. Bug: 274825778 Change-Id: I11edf6e50411a05c6723f7523f3672a9a8116d7a --- conf/fstab.gs201.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/fstab.gs201.in b/conf/fstab.gs201.in index e1af3e8b..88a17127 100644 --- a/conf/fstab.gs201.in +++ b/conf/fstab.gs201.in @@ -5,11 +5,11 @@ # # system /system ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 -system_dlkm /system_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 +system_dlkm /system_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta_system,avb_keys=/avb,logical,first_stage_mount,readahead_size_kb=128 system_ext /system_ext ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 product /product ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 vendor /vendor ext4 noatime,ro wait,slotselect,avb=vbmeta_vendor,logical,first_stage_mount,readahead_size_kb=128 -vendor_dlkm /vendor_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta,logical,first_stage_mount +vendor_dlkm /vendor_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta,avb_keys=/avb,logical,first_stage_mount /dev/block/platform/14700000.ufs/by-name/boot /boot emmc defaults slotselect,avb=boot,first_stage_mount /dev/block/platform/14700000.ufs/by-name/init_boot /init_boot emmc defaults slotselect,avb=init_boot,first_stage_mount /dev/block/platform/14700000.ufs/by-name/misc /misc emmc defaults wait From c88501a60669b0e7deba8fb1d1d868803b22622f Mon Sep 17 00:00:00 2001 From: William McVicker Date: Thu, 19 Oct 2023 17:02:25 +0000 Subject: [PATCH 46/74] Revert "fstab: allow unlocked devices to boot with AVB test key" This reverts commit c13cd03ccf360755bcebaa0df94427a3ac81217e. Reason for revert: Let's go through a proper security review for this. Bug: 306264015 Change-Id: I51fe3f32f8a4ec92cb2d38869568a51dc2522bb4 --- conf/fstab.gs201.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/fstab.gs201.in b/conf/fstab.gs201.in index 88a17127..e1af3e8b 100644 --- a/conf/fstab.gs201.in +++ b/conf/fstab.gs201.in @@ -5,11 +5,11 @@ # # system /system ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 -system_dlkm /system_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta_system,avb_keys=/avb,logical,first_stage_mount,readahead_size_kb=128 +system_dlkm /system_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 system_ext /system_ext ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 product /product ext4 noatime,ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount,readahead_size_kb=128 vendor /vendor ext4 noatime,ro wait,slotselect,avb=vbmeta_vendor,logical,first_stage_mount,readahead_size_kb=128 -vendor_dlkm /vendor_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta,avb_keys=/avb,logical,first_stage_mount +vendor_dlkm /vendor_dlkm ext4 noatime,ro wait,slotselect,avb=vbmeta,logical,first_stage_mount /dev/block/platform/14700000.ufs/by-name/boot /boot emmc defaults slotselect,avb=boot,first_stage_mount /dev/block/platform/14700000.ufs/by-name/init_boot /init_boot emmc defaults slotselect,avb=init_boot,first_stage_mount /dev/block/platform/14700000.ufs/by-name/misc /misc emmc defaults wait From 8135bd2ba4d850435c178293d2c466709908abff Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 6 Oct 2023 07:01:52 +0000 Subject: [PATCH 47/74] Update IDisplay to V10 Test: Build pass Bug: 299410182 Change-Id: Ic4ffb1139861fc805283421b3e6fa48cb3f30f4a Signed-off-by: Leo Chen --- device_framework_matrix_product.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index 4f64efae..fb2cbaea 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -78,7 +78,7 @@ com.google.hardware.pixel.display - 9 + 10 IDisplay default From d9437fa21f5cf63fa75dce8615448a5fa2962686 Mon Sep 17 00:00:00 2001 From: Jenny Ho Date: Wed, 25 Oct 2023 15:14:06 +0800 Subject: [PATCH 48/74] pixelstats: add gmsr path Bug: 300590097 Change-Id: I585de78116d750fdea7e310c62ce91f98c0b9540 Signed-off-by: Jenny Ho --- pixelstats/service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index b7df808e..7c53cb2e 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -83,7 +83,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics", .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset", .ModemPcieLinkStatsPath = "/sys/devices/platform/11920000.pcie/link_stats", - .WifiPcieLinkStatsPath = "/sys/devices/platform/14520000.pcie/link_stats" + .WifiPcieLinkStatsPath = "/sys/devices/platform/14520000.pcie/link_stats", + .GMSRPath = "/sys/class/power_supply/maxfg/gmsr" }; const struct UeventListener::UeventPaths ueventPaths = { From e4a81c0e8f9f8d89f0e42e8fd7ec40cec6b887ed Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Tue, 24 Oct 2023 07:59:40 -0700 Subject: [PATCH 49/74] Run fsck to resolve possible data corruption Trigger fsck on mount of /data if the value of ro.preventative_fsck is not equal to the contents of /metadata/vold/preventative_fsck, then set the file to the property to prevent future runs See b/305658663 for context Bug: 305658663 Test: Make sure fsck run after first boot and not after second Change-Id: I1263d2d55fe22d994ae8c8654b1e75ad9e4ddafe --- device-common.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device-common.mk b/device-common.mk index 56b2e0ec..c1d18881 100644 --- a/device-common.mk +++ b/device-common.mk @@ -51,3 +51,7 @@ PRODUCT_PRODUCT_PROPERTIES += \ # Set thermal warm reset PRODUCT_PRODUCT_PROPERTIES += \ ro.thermal_warmreset = true + +# Trigger fsck on upgrade (305658663) +PRODUCT_PRODUCT_PROPERTIES += \ + ro.preventative_fsck = 1 \ No newline at end of file From 39337da9be1c3193aa862b35aa291ffc0083c241 Mon Sep 17 00:00:00 2001 From: Will Song Date: Fri, 27 Oct 2023 21:52:45 +0000 Subject: [PATCH 50/74] PREUPLOAD: Enforce jsonlint in preupload Checks syntax and simple brace balances for all JSON files. Test: Edit any json and try upload Bug: 127794899 Change-Id: I12e5ca0a0fe249f7d93adbd540d4964cafb09249 --- PREUPLOAD.cfg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 PREUPLOAD.cfg diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg new file mode 100644 index 00000000..37ebb5e7 --- /dev/null +++ b/PREUPLOAD.cfg @@ -0,0 +1,2 @@ +[Builtin Hooks] +jsonlint = true From 96a9ee2a1824f8877dc32eb6916bc8de997b0215 Mon Sep 17 00:00:00 2001 From: mincheli Date: Mon, 23 Oct 2023 18:30:05 +0800 Subject: [PATCH 51/74] gs201 includes TTS voice packs from gs-common/device.mk Bug: 140145973 Test: manual test Change-Id: I8207ccc370e1f8d811273f0773851f42b945ccd4 --- device-common.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/device-common.mk b/device-common.mk index bfd64abb..55f5020d 100644 --- a/device-common.mk +++ b/device-common.mk @@ -18,7 +18,6 @@ ifneq ($(BOARD_WITHOUT_RADIO),true) -include vendor/google_devices/gs201/proprietary/telephony/device-vendor.mk endif include device/google/gs201/device.mk -include device/google/gs101/tts/voice_packs.mk ifneq ($(BOARD_WITHOUT_RADIO),true) # Telephony From 6c78c45aaec9e4c94739b493f1da040e28cbc6ce Mon Sep 17 00:00:00 2001 From: George Lee Date: Tue, 31 Oct 2023 02:54:32 +0000 Subject: [PATCH 52/74] pixelstats: Add brownout detection path Bug: 307392882 Test: Local generate brownout for data upload Change-Id: I06b846b9a0a9d8eb4edd5e1636248a44940f0683 Signed-off-by: George Lee --- pixelstats/service.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index 7c53cb2e..5d739b18 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -44,6 +44,10 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .ImpedancePath = "/sys/devices/platform/audiometrics/speaker_impedance", .CodecPath = "/sys/devices/platform/audiometrics/codec_state", .EEPROMPath = "/dev/battery_history", + .MitigationPath = "/sys/devices/virtual/pmic/mitigation", + .MitigationDurationPath = "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt", + .BrownoutReasonProp = "vendor.brownout_reason", + .BrownoutLogPath = "/data/vendor/mitigation/lastmeal.txt", .SpeakerTemperaturePath = "/sys/devices/platform/audiometrics/speaker_temp", .SpeakerExcursionPath = "/sys/devices/platform/audiometrics/speaker_excursion", .SpeakerHeartBeatPath = "/sys/devices/platform/audiometrics/speaker_heartbeat", From 2f628f5fd2a9e6faaa0250a0cf3efe373c77412c Mon Sep 17 00:00:00 2001 From: Jasmine Cha Date: Wed, 18 Oct 2023 13:29:32 +0800 Subject: [PATCH 53/74] audio: remove prescale for BT absolute volume Bug: 302553525 Test: build pass Change-Id: I55ed6d8f96ccfca74317b70bc9b5a2ff28bbba50 Signed-off-by: Jasmine Cha --- overlay/frameworks/base/core/res/res/values/config.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index b35e3f20..5a96957d 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -305,4 +305,13 @@ com.bilibili.app.in:0.07 com.twitter.android:0.07 + + + 100% + + + 100% + + + 100% From 5187b301cb14094775c749987e98d6f1f9b79e98 Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Wed, 1 Nov 2023 06:11:56 +0000 Subject: [PATCH 54/74] Update default allow list for VRR small dirty detection The feature will be enabled by the feature flag Bug: 308742727 Test: Build Change-Id: Iff7cfbe3ebc2e6acbfafc0b44b57dc446cca1f89 --- overlay/frameworks/base/core/res/res/values/config.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 5a96957d..f2ed7789 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -298,7 +298,9 @@ be between 0 to 1--> - com.google.android.youtube:0.07 + com.tencent.mm:0.07 + com.facebook.katana:0.07 + com.instagram.android:0.07 com.spotify.music:0.05 com.reddit.frontpage:0.07 com.zhiliaoapp.musically:0.07 From 4217a458ba8584d5b8ed03d3acc3ba261f90c67b Mon Sep 17 00:00:00 2001 From: Devika Krishnadas Date: Tue, 7 Nov 2023 03:57:41 +0000 Subject: [PATCH 55/74] Revert^2 "Use graphics allocator 2" d2adab192e35bd21d2f7271420fc97bc9452802d Bug: 287353739 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: I8e43a268441416af28631777f560352bc56b2773 Signed-off-by: Devika Krishnadas --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index e9ca7a99..4342a53a 100644 --- a/device.mk +++ b/device.mk @@ -516,7 +516,7 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.graphics.mapper@4.0-impl \ - android.hardware.graphics.allocator-V1-service + android.hardware.graphics.allocator-V2-service PRODUCT_PACKAGES += \ android.hardware.memtrack-service.pixel \ From 91c045df5b94f489251b1a8706544565b7471cb7 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Mon, 6 Nov 2023 23:12:46 +0000 Subject: [PATCH 56/74] usb: update incompatible charger warning reason Report COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of COMPLIANCE_WARNING_OTHER to flag incompatible chargers. The underlying logic that generates the warning remains the same, what's changed is the enum that's being used. The purpose of the change is to have a warning type that better represents what actually happens and free up COMPLIANCE_WARNING_OTHER that was intended to act as a fallback reason code. The flag enable_input_power_limited_warning controls whether to switch to the new enum, while the flag enable_usb_data_compliance_warning controls the new enums that are added as FlaggedApi in the framework. Both flags need to be on to enable the change. Bug: 308700954 Test: manual tests with local flag override Change-Id: I6595706d1b83d533fc2d3e29086773270e045ede --- usb/usb/Android.bp | 12 ++++++++++-- usb/usb/Usb.cpp | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index e28667fc..8fd373b2 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -47,21 +47,29 @@ cc_binary { "android.hardware.thermal@2.0", "android.hardware.thermal-V1-ndk", "android.hardware.usb.gadget@1.0", - "android.hardware.usb-V2-ndk", + "android.hardware.usb-V3-ndk", "android.hardware.usb.gadget-V1-ndk", "libcutils", "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", "libbinder_ndk", - "libprotobuf-cpp-lite", + "libprotobuf-cpp-lite", + "server_configurable_flags", ], static_libs: [ "libpixelusb-aidl", "libpixelstats", "libthermalutils", + "android.hardware.usb.flags-aconfig-c-lib", ], export_shared_lib_headers: [ "android.frameworks.stats-V2-ndk", "pixelatoms-cpp", ], } + +cc_aconfig_library { + name: "android.hardware.usb.flags-aconfig-c-lib", + vendor: true, + aconfig_declarations: "android.hardware.usb.flags-aconfig", +} diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 9aa09da0..224951a1 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -43,10 +43,13 @@ #include "Usb.h" #include +#include #include #include #include +namespace usb_flags = android::hardware::usb::flags; + using aidl::android::frameworks::stats::IStats; using android::base::GetProperty; using android::base::Tokenize; @@ -75,6 +78,7 @@ constexpr char kComplianceWarningBC12[] = "bc12"; constexpr char kComplianceWarningDebugAccessory[] = "debug-accessory"; constexpr char kComplianceWarningMissingRp[] = "missing_rp"; constexpr char kComplianceWarningOther[] = "other"; +constexpr char kComplianceWarningInputPowerLimited[] = "input_power_limited"; constexpr char kContaminantDetectionPath[] = "i2c-max77759tcpc/contaminant_detection"; constexpr char kStatusPath[] = "i2c-max77759tcpc/contaminant_detection_status"; constexpr char kSinkLimitEnable[] = "i2c-max77759tcpc/usb_limit_sink_enable"; @@ -333,9 +337,20 @@ Status queryNonCompliantChargerStatus(std::vector *currentPortStatus continue; } if (!strncmp(reason.c_str(), kComplianceWarningOther, - strlen(kComplianceWarningOther))) { - (*currentPortStatus)[i].complianceWarnings.push_back(ComplianceWarning::OTHER); - continue; + strlen(kComplianceWarningOther)) || + !strncmp(reason.c_str(), kComplianceWarningInputPowerLimited, + strlen(kComplianceWarningInputPowerLimited))) { + if (usb_flags::enable_usb_data_compliance_warning() && + usb_flags::enable_input_power_limited_warning()) { + ALOGI("Report through INPUT_POWER_LIMITED warning"); + (*currentPortStatus)[i].complianceWarnings.push_back( + ComplianceWarning::INPUT_POWER_LIMITED); + continue; + } else { + (*currentPortStatus)[i].complianceWarnings.push_back( + ComplianceWarning::OTHER); + continue; + } } } if ((*currentPortStatus)[i].complianceWarnings.size() > 0 && From 6d978bc632f1b89712a27c19a585a173f1a3f871 Mon Sep 17 00:00:00 2001 From: Jack Wu Date: Fri, 10 Nov 2023 20:32:29 +0800 Subject: [PATCH 57/74] gs201: update AIDL IGoogleBattery manifest version to 3 Bug: 309518527 Test: TH Change-Id: I25f671b2c9cf3998288377c972a490748da0c627 Signed-off-by: Jack Wu --- device_framework_matrix_product.xml | 2 +- manifest-gralloc3.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/device_framework_matrix_product.xml b/device_framework_matrix_product.xml index fb2cbaea..1e34caf2 100644 --- a/device_framework_matrix_product.xml +++ b/device_framework_matrix_product.xml @@ -110,7 +110,7 @@ vendor.google.google_battery - 2 + 2-3 IGoogleBattery default diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index fee04558..82ff14ab 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -97,7 +97,7 @@ vendor.google.google_battery - 2 + 2-3 IGoogleBattery default From a99d48c10eda22276d4401716a83aa74b88423c7 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Tue, 14 Nov 2023 20:43:36 +0000 Subject: [PATCH 58/74] usb: update usb hal version to v3 Bug: 308700954 Test: atest vts_treble_vintf_vendor_test Change-Id: I13c99d309b925520b529ec2e22a120adc5e834e7 --- usb/usb/android.hardware.usb-service.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb/usb/android.hardware.usb-service.xml b/usb/usb/android.hardware.usb-service.xml index c3f07f52..7ac20679 100644 --- a/usb/usb/android.hardware.usb-service.xml +++ b/usb/usb/android.hardware.usb-service.xml @@ -1,7 +1,7 @@ android.hardware.usb - 2 + 3 IUsb default From b4cd7bf61985a8fa4d2ba16cf434df10caece9a7 Mon Sep 17 00:00:00 2001 From: Jerry Huang Date: Wed, 15 Nov 2023 11:52:59 +0000 Subject: [PATCH 59/74] gs201: add c2.android.av1-dav1d.decoder in media_codecs_performance_c2.xml c2.android.av1-dav1d.decoder is based on dav1d implementation. This dav1d-based sw av1 decoder provides better decoding throughput than the default gav1-based av1 decoder on mid-to-low-tier devices. c2.android.av1.decoder will be deprecate eventually before that we keep both decoders. Bug: 309412792 Test: run cts -m CtsMediaDecoderTestCases -t android.media.decoder.cts.VideoDecoderPerfTest --module-arg CtsMediaDecoderTestCases:instrumentation-arg:codec-prefix:=c2.android.av1.decoder Change-Id: Idc841e76425f333e16cc701869f450f126b2d72d --- media_codecs_performance_c2.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/media_codecs_performance_c2.xml b/media_codecs_performance_c2.xml index 13609f2b..12dde41e 100644 --- a/media_codecs_performance_c2.xml +++ b/media_codecs_performance_c2.xml @@ -173,6 +173,12 @@ + + + + + + From 1ecee14a460227baf7473ec9b4da325fb495c814 Mon Sep 17 00:00:00 2001 From: Ruofei Ma Date: Fri, 17 Nov 2023 22:05:17 +0000 Subject: [PATCH 60/74] Enable adaptive playback for BigOcean Bug: 309722491 Change-Id: I8d402be86027ab20b2b633c1a97c6afb8fc13a16 Signed-off-by: Ruofei Ma --- media_codecs_bo_c2.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/media_codecs_bo_c2.xml b/media_codecs_bo_c2.xml index b57a92aa..3a397263 100644 --- a/media_codecs_bo_c2.xml +++ b/media_codecs_bo_c2.xml @@ -29,7 +29,7 @@ - + @@ -43,7 +43,7 @@ - + From baca0e0e4d09bf5bd2dd2e595df44f00c4ead65c Mon Sep 17 00:00:00 2001 From: Edgar Arriaga Date: Wed, 25 Oct 2023 20:43:26 +0000 Subject: [PATCH 61/74] Add webview pinning for gs201 devices Bug: 307594624 Change-Id: I13f4c2020b699f68a679fd34f4f6b025c0bfdb98 --- overlay/frameworks/base/core/res/res/values/config.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index f2ed7789..82cb06dd 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -252,6 +252,9 @@ true + + 20971520 + From ad362cf2590b84b39519c45d298dfe5ad9752946 Mon Sep 17 00:00:00 2001 From: Peter Lin Date: Thu, 30 Nov 2023 07:50:38 +0000 Subject: [PATCH 62/74] Update default color temperature for night light Bug: 302396607 Test: adb shell dumpsys color_display | grep "Color temp" Change-Id: I7812dcea6e2d6bceab13d9f103e434e19b6e9477 --- overlay/frameworks/base/core/res/res/values/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 82cb06dd..e9e4f01b 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -215,7 +215,7 @@ - 3339 + 4000 true From 3555bbe0a8ef335a95080b8b91cd3e8257785365 Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Tue, 14 Nov 2023 18:49:06 +0000 Subject: [PATCH 63/74] usb: introduce UsbDataSessionMonitor class Migrate the usb data session event functions to the class with the following additional functionalities; - Support detecting gadget soft pulldown (usually done during configfs function switch) and report usb data session correctly. - Support reporting usb data compliance warnings to the class USB by providing getDataComplianceWarnings call. - Use boot_clock instead of steady_clock to measure time correctly in the case of system suspend. UsbDataSessionMonitor is self-contained and can be migrated to pixel usb library after feature maturation. Bug: 297224564 Bug: 296119135 Test: usb data session upload in device and host mode Change-Id: Iba001933e193935d64cf5fd0a1257d02a4274fb1 (cherry picked from commit ea65ca11f6fbb6f13b89ef9ed03015f47ec1cedb) --- usb/usb/Android.bp | 1 + usb/usb/Usb.cpp | 308 +++++----------------- usb/usb/Usb.h | 34 +-- usb/usb/UsbDataSessionMonitor.cpp | 420 ++++++++++++++++++++++++++++++ usb/usb/UsbDataSessionMonitor.h | 114 ++++++++ 5 files changed, 598 insertions(+), 279 deletions(-) create mode 100644 usb/usb/UsbDataSessionMonitor.cpp create mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 8fd373b2..609af179 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,6 +34,7 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", + "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 224951a1..555e6576 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,6 @@ #include #include -#include #include #include @@ -57,9 +55,6 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; using android::String8; using android::Vector; @@ -95,17 +90,22 @@ constexpr char kThermalZoneForTempReadSecondary2[] = "qi_therm"; constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_active"; constexpr char KPogoMoveDataToUsb[] = "/sys/devices/platform/google,pogo/move_data_to_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; -constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -// xhci-hcd-exynos and usb device numbering could vary on different platforms -constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; +constexpr char kUdcUeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; +constexpr char kUdcStatePath[] = + "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +constexpr char kHost1UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; +constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; +constexpr char kHost2UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb3/3-0:1.0"; +constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb3/3-0:1.0/usb3-port1/state"; +constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus); -#define USB_STATE_MAX_LEN 20 #define CTRL_TRANSFER_TIMEOUT_MSEC 1000 #define GL852G_VENDOR_ID 0x05e3 #define GL852G_PRODUCT_ID1 0x0608 @@ -538,11 +538,20 @@ void *usbHostWork(void *param) { return NULL; } +void updatePortStatus(android::hardware::usb::Usb *usb) { + std::vector currentPortStatus; + + queryVersionHelper(usb, ¤tPortStatus); +} + Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), + mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, + kHost2UeventRegex, kHost2StatePath, kDataRolePath, + std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -922,6 +931,18 @@ done: return Status::ERROR; } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + std::vector warnings; + + usb->mUsbDataSessionMonitor.getComplianceWarnings( + (*currentPortStatus)[0].currentDataRole, &warnings); + (*currentPortStatus)[0].complianceWarnings.insert( + (*currentPortStatus)[0].complianceWarnings.end(), + warnings.begin(), + warnings.end()); +} + void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1017,194 +1038,17 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -void report_usb_data_session_event(android::hardware::usb::Usb *usb) { - std::vector events; +struct data { + int uevent_fd; + ::aidl::android::hardware::usb::Usb *usb; +}; - if (usb->mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &usb->mDeviceState.states, - &usb->mDeviceState.timestamps, &event); - events.push_back(event); - } else if (usb->mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto &entry : usb->mHostStateMap) { - // Host port will at least get an not_attached event after enablement, - // skip upload if no additional state is added. - if (entry.second.states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &entry.second.states, - &entry.second.timestamps, &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty && usb->mHostStateMap.size() > 0) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, - &usb->mHostStateMap.begin()->second.states, - &usb->mHostStateMap.begin()->second.timestamps, - &event); - events.push_back(event); - } - } else { - return; - } - - const shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - -static void unregisterEpollEntry(Usb *usb, std::string name) { - std::map *map; - int fd; - - map = &usb->mEpollEntries; - auto it = map->find(name); - if (it != map->end()) { - ALOGI("epoll unregister %s", name.c_str()); - fd = it->second.payload.fd; - epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); - close(fd); - map->erase(it); - } -} - -static void unregisterEpollEntries(Usb *usb) { - std::map *map; - std::string name; - - map = &usb->mEpollEntries; - for (auto it = map->begin(); it != map->end();) { - name = it->first; - it++; - unregisterEpollEntry(usb, name); - } -} - -static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - std::map *map; - struct Usb::epollEntry *entry; - struct epoll_event ev; - - map = &usb->mEpollEntries; - if (map->find(name) != map->end()) { - ALOGE("%s already registered", name.c_str()); - unregisterEpollEntry(usb, name); - } - - entry = &(*map)[name]; - entry->payload.fd = fd; - entry->payload.name = name; - entry->payload.usb = usb; - entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); - - ev.events = flags; - ev.data.ptr = (void *)&entry->cb; - - if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - unregisterEpollEntry(usb, name); - return -1; - } - - ALOGI("epoll register %s", name.c_str()); - - return 0; -} - -static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - int fd; - - fd = open(name.c_str(), O_RDONLY); - if (fd < 0) { - ALOGE("Cannot open %s", name.c_str()); - return -1; - } - - return registerEpollEntry(usb, name, fd, flags, func); -} - -static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->states.clear(); - device->timestamps.clear(); - device->portResetCount = 0; -} - -static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { - ALOGI("Update USB device state: %s", state); - - device->states.push_back(state); - device->timestamps.push_back(std::chrono::steady_clock::now()); - - if (!std::strcmp(state, "configured\n")) { - device->portResetCount = 0; - } else if (!std::strcmp(state, "default\n")) { - device->portResetCount++; - } -} - -static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - struct Usb::usbDeviceState *device; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); -} - -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; - PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; - - if (newDataRole != usb->mDataRole) { - // Upload metrics for the last non-powerbrick data session that has ended - if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { - report_usb_data_session_event(usb); - } - - // Set up for the new data session - usb->mDataRole = newDataRole; - usb->mDataSessionStart = std::chrono::steady_clock::now(); - usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); - if (newDataRole == PortDataRole::DEVICE) { - clearUsbDeviceState(&usb->mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - for (auto &entry : usb->mHostStateMap) { - clearUsbDeviceState(&entry.second); - } - } - } - - // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data - // session when BC1.2 SDP times out and falls back to DCP - if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { - usb->mIsPowerBrickConnected = true; - } -} - -static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { +static void uevent_event(uint32_t /*epevents*/, struct data *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; - std::cmatch match; - n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1250,28 +1094,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } else if (!strncmp(cp, kOverheatStatsDev, strlen(kOverheatStatsDev))) { ALOGV("Overheat Cooling device suez update"); report_overheat_event(payload->usb); - } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { - /* - * Matched strings: - * 1st: entire string - * 2nd: uevent action, either "bind" or "unbind" - * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto - * 4th: usb device number, e.g. 1 for usb1 - * - * The strings are used to composed usb device state path, e.g. - * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state - */ - if (match.size() == 4) { - std::string action = match[1].str(); - std::string id = match[3].str(); - std::string path = "/sys" + match[2].str() + "usb" + id + "/" + - id + "-0:1.0/usb" + id + "-port1/state"; - if (action == "bind") { - registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); - } else if (action == "unbind") { - unregisterEpollEntry(payload->usb, path); - } - } } /* advance to after the next \0 */ while (*cp++) { @@ -1279,46 +1101,37 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } } -static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mDeviceState, state); -} - void *work(void *param) { int epoll_fd, uevent_fd; + struct epoll_event ev; int nevents = 0; - Usb *usb = (Usb *)param; + struct data payload; ALOGE("creating thread"); + uevent_fd = uevent_open_socket(64 * 1024, true); + + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed\n"); + return NULL; + } + + payload.uevent_fd = uevent_fd; + payload.usb = (::aidl::android::hardware::usb::Usb *)param; + + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + ev.events = EPOLLIN; + ev.data.ptr = (void *)uevent_event; + epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); - return NULL; - } - usb->mEpollFd = epoll_fd; - - // Monitor uevent - uevent_fd = uevent_open_socket(64 * 1024, true); - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed"); - goto error; - } - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { - ALOGE("failed to monitor uevent"); goto error; } - // Monitor udc state - if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { - ALOGE("failed to monitor udc state"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { + ALOGE("epoll_ctl failed; errno=%d", errno); goto error; } @@ -1335,15 +1148,14 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(std::function*)events[n].data.ptr)(events[n].events); + (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, + &payload); } } ALOGI("exiting worker thread"); error: - unregisterEpollEntries(usb); - - usb->mEpollFd = -1; + close(uevent_fd); if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 83bae889..495a467f 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,9 +19,9 @@ #include #include #include -#include #include #include +#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -88,6 +88,8 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; + // Report usb data session event and data incompliance warnings + UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -98,36 +100,6 @@ struct Usb : public BnUsb { int mUsbHubVendorCmdValue; int mUsbHubVendorCmdIndex; - // USB device state monitoring - struct usbDeviceState { - // Usb device state raw strings read from sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - int portResetCount; - }; - struct usbDeviceState mDeviceState; - // Map host device path name to usbDeviceState - std::map mHostStateMap; - // Cache relevant info for USB data session metrics collection when a session starts, including - // the data role, power brick status and the time when the session starts. - PortDataRole mDataRole; - bool mIsPowerBrickConnected; - std::chrono::steady_clock::time_point mDataSessionStart; - - // File monitoring through epoll - int mEpollFd; - struct payload { - int fd; - std::string name; - Usb *usb; - }; - struct epollEntry { - struct payload payload; - std::function cb; - }; - std::map mEpollEntries; - private: pthread_t mPoll; pthread_t mUsbHost; diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp new file mode 100644 index 00000000..77defb30 --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2023 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. + */ + +#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" + +#include "UsbDataSessionMonitor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace usb_flags = android::hardware::usb::flags; + +using aidl::android::frameworks::stats::IStats; +using android::base::ReadFileToString; +using android::hardware::google::pixel::getStatsService; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::usb::addEpollFd; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +#define UEVENT_MSG_LEN 2048 +#define USB_STATE_MAX_LEN 20 +#define DATA_ROLE_MAX_LEN 10 + +constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; +constexpr char kNotAttachedState[] = "not attached\n"; +constexpr char kAttachedState[] = "attached\n"; +constexpr char kPoweredState[] = "powered\n"; +constexpr char kDefaultState[] = "default\n"; +constexpr char kAddressedState[] = "addressed\n"; +constexpr char kConfiguredState[] = "configured\n"; +constexpr char kSuspendedState[] = "suspended\n"; +const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, + kDefaultState, kAddressedState, kConfiguredState, + kSuspendedState}; + +static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + struct epoll_event ev; + + unique_fd fd(open(filePath.c_str(), O_RDONLY)); + + if (fd.get() == -1) { + ALOGI("Cannot open %s", filePath.c_str()); + return -1; + } + + ev.data.fd = fd.get(); + ev.events = EPOLLPRI; + + if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + return -1; + } + + fileFd = std::move(fd); + ALOGI("epoll registered %s", filePath.c_str()); + return 0; +} + +static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); + fileFd.release(); + + ALOGI("epoll unregistered %s", filePath.c_str()); +} + +UsbDataSessionMonitor::UsbDataSessionMonitor( + const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, std::function updatePortStatusCb) { + struct epoll_event ev; + std::string udc; + + unique_fd epollFd(epoll_create(8)); + if (epollFd.get() == -1) { + ALOGE("epoll_create failed; errno=%d", errno); + abort(); + } + + unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); + if (ueventFd.get() == -1) { + ALOGE("uevent_open_socket failed"); + abort(); + } + fcntl(ueventFd, F_SETFL, O_NONBLOCK); + + if (addEpollFd(epollFd, ueventFd)) + abort(); + + if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { + ALOGE("monitor data role failed"); + abort(); + } + + /* + * The device state file could be absent depending on the current data role + * and driver architecture. It's ok for addEpollFile to fail here, the file + * will be monitored later when its presence is detected by uevent. + */ + mDeviceState.filePath = deviceStatePath; + mDeviceState.ueventRegex = deviceUeventRegex; + addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); + + mHost1State.filePath = host1StatePath; + mHost1State.ueventRegex = host1UeventRegex; + addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); + + mHost2State.filePath = host2StatePath; + mHost2State.ueventRegex = host2UeventRegex; + addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); + + mEpollFd = std::move(epollFd); + mUeventFd = std::move(ueventFd); + mUpdatePortStatusCb = updatePortStatusCb; + + if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) + mUdcBind = true; + else + mUdcBind = false; + + if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { + ALOGE("pthread creation failed %d", errno); + abort(); + } +} + +UsbDataSessionMonitor::~UsbDataSessionMonitor() {} + +void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { + std::vector events; + + if (mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, + &mDeviceState.states, &mDeviceState.timestamps, &event); + events.push_back(event); + } else if (mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto e : {&mHost1State, &mHost2State}) { + /* + * Host port will at least get an not_attached event after enablement, + * skip upload if no additional state is added. + */ + if (e->states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), + mDataSessionStart, &e->states, &e->timestamps, + &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, + &mHost1State.states, &mHost1State.timestamps, &event); + events.push_back(event); + } + } else { + return; + } + + const std::shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + +void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, + std::vector *warnings) { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (role != mDataRole || role == PortDataRole::NONE) + return; + + for (auto w : mWarningSet) { + warnings->push_back(w); + } +} + +void UsbDataSessionMonitor::notifyComplianceWarning() { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (mUpdatePortStatusCb) + mUpdatePortStatusCb(); +} + +void UsbDataSessionMonitor::evaluateComplianceWarning() { + std::set newWarningSet; + + // TODO: add heuristics and update newWarningSet + if (mDataRole == PortDataRole::DEVICE && mUdcBind) { + } else if (mDataRole == PortDataRole::HOST) { + } + + if (newWarningSet != mWarningSet) { + mWarningSet = newWarningSet; + notifyComplianceWarning(); + } +} + +void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { + deviceState->states.clear(); + deviceState->timestamps.clear(); +} + +void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(deviceState->fd.get(), 0, SEEK_SET); + n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); + + if (kValidStates.find(state) == kValidStates.end()) { + ALOGE("Invalid state %s", state); + return; + } + + ALOGI("Update USB device state: %s", state); + + deviceState->states.push_back(state); + deviceState->timestamps.push_back(boot_clock::now()); + evaluateComplianceWarning(); +} + +void UsbDataSessionMonitor::handleDataRoleEvent() { + int n; + PortDataRole newDataRole; + char role[DATA_ROLE_MAX_LEN] = {0}; + + lseek(mDataRoleFd.get(), 0, SEEK_SET); + n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); + + ALOGI("Update USB data role %s", role); + + if (!std::strcmp(role, "host")) { + newDataRole = PortDataRole::HOST; + } else if (!std::strcmp(role, "device")) { + newDataRole = PortDataRole::DEVICE; + } else { + newDataRole = PortDataRole::NONE; + } + + if (newDataRole != mDataRole) { + // Upload metrics for the last data session that has ended + if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { + reportUsbDataSessionMetrics(); + } + + // Set up for the new data session + mWarningSet.clear(); + mDataRole = newDataRole; + mDataSessionStart = boot_clock::now(); + + if (newDataRole == PortDataRole::DEVICE) { + clearDeviceStateEvents(&mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + clearDeviceStateEvents(&mHost1State); + clearDeviceStateEvents(&mHost2State); + } + } +} + +void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { + std::string function; + bool newUdcBind; + + /* + * /sys/class/udc//function prints out name of currently running USB gadget driver + * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc + * Empty name string means the udc device is not bound and gadget is pulldown. + */ + if (!ReadFileToString("/sys" + devname + "/function", &function)) + return; + + if (function == "") + newUdcBind = false; + else + newUdcBind = true; + + if (newUdcBind == mUdcBind) + return; + + if (mDataRole == PortDataRole::DEVICE) { + if (mUdcBind && !newUdcBind) { + /* + * Gadget soft pulldown: report metrics as the end of a data session and + * re-evaluate compliance warnings to clear existing warnings if any. + */ + reportUsbDataSessionMetrics(); + evaluateComplianceWarning(); + + } else if (!mUdcBind && newUdcBind) { + // Gadget soft pullup: reset and start accounting for a new data session. + clearDeviceStateEvents(&mDeviceState); + mDataSessionStart = boot_clock::now(); + } + } + + ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); + mUdcBind = newUdcBind; +} + +void UsbDataSessionMonitor::handleUevent() { + char msg[UEVENT_MSG_LEN + 2]; + char *cp; + int n; + + n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); + if (n <= 0) + return; + if (n >= UEVENT_MSG_LEN) + return; + + msg[n] = '\0'; + msg[n + 1] = '\0'; + cp = msg; + + while (*cp) { + for (auto e : {&mHost1State, &mHost2State}) { + if (std::regex_search(cp, std::regex(e->ueventRegex))) { + if (!strncmp(cp, "bind@", strlen("bind@"))) { + addEpollFile(mEpollFd.get(), e->filePath, e->fd); + } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { + removeEpollFile(mEpollFd.get(), e->filePath, e->fd); + } + } + } + + // TODO: support bind@ unbind@ to detect dynamically allocated udc device + if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { + if (!strncmp(cp, "change@", strlen("change@"))) { + char *devname = cp + strlen("change@"); + /* + * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. + * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually + * executed. Add a short delay to get the correct state while working on a fix + * upstream. + */ + usleep(50000); + updateUdcBindStatus(devname); + } + } + /* advance to after the next \0 */ + while (*cp++) { + } + } +} + +void *UsbDataSessionMonitor::monitorThread(void *param) { + UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; + struct epoll_event events[64]; + int nevents = 0; + + while (true) { + nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); + if (nevents == -1) { + if (errno == EINTR) + continue; + ALOGE("usb epoll_wait failed; errno=%d", errno); + break; + } + + for (int n = 0; n < nevents; ++n) { + if (events[n].data.fd == monitor->mUeventFd.get()) { + monitor->handleUevent(); + } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { + monitor->handleDataRoleEvent(); + } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mDeviceState); + } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost1State); + } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost2State); + } + } + } + return NULL; +} + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h new file mode 100644 index 00000000..596f378f --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 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. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +using ::aidl::android::hardware::usb::ComplianceWarning; +using ::aidl::android::hardware::usb::PortDataRole; +using ::android::base::boot_clock; +using ::android::base::unique_fd; + +/* + * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices + * including device mode (udc), host mode high-speed port and host mode super-speed port. It + * reports Suez metrics for each data session and also provides API to query the compliance + * warnings detected in the current usb data session. + */ +class UsbDataSessionMonitor { + public: + /* + * The host mode high-speed port and super-speed port can be assigned to either host1 or + * host2 without affecting functionality. + * + * UeventRegex: name regex of the device that's being monitored. The regex is matched against + * uevent to detect dynamic creation/deletion/change of the device. + * StatePath: usb device state sysfs path of the device, monitored by epoll. + * dataRolePath: path to the usb data role sysfs, monitored by epoll. + * updatePortStatusCb: the callback is invoked when the compliance warings changes. + */ + UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, + std::function updatePortStatusCb); + ~UsbDataSessionMonitor(); + // Returns the compliance warnings detected in the current data session. + void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); + + private: + struct usbDeviceState { + unique_fd fd; + std::string filePath; + std::string ueventRegex; + // Usb device states reported by state sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + }; + + static void *monitorThread(void *param); + void handleUevent(); + void handleDataRoleEvent(); + void handleDeviceStateEvent(struct usbDeviceState *deviceState); + void clearDeviceStateEvents(struct usbDeviceState *deviceState); + void reportUsbDataSessionMetrics(); + void evaluateComplianceWarning(); + void notifyComplianceWarning(); + void updateUdcBindStatus(const std::string &devname); + + pthread_t mMonitor; + unique_fd mEpollFd; + unique_fd mUeventFd; + unique_fd mDataRoleFd; + struct usbDeviceState mDeviceState; + struct usbDeviceState mHost1State; + struct usbDeviceState mHost2State; + std::set mWarningSet; + // Callback function to notify the caller when there's a change in compliance warnings. + std::function mUpdatePortStatusCb; + /* + * Cache relevant info for a USB data session when one starts, including + * the data role and the time when the session starts. + */ + PortDataRole mDataRole; + boot_clock::time_point mDataSessionStart; + /* + * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which + * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, + * the gadget is in soft pulldown state and is expected not to enumerate. During gadget + * function switch, the udc device usually go through unbind and bind. + */ + bool mUdcBind; +}; + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl From c41e6f519bc79da4a1578a88a68f17d604660a3b Mon Sep 17 00:00:00 2001 From: Hiroshi Akiyama Date: Thu, 30 Nov 2023 19:44:58 +0000 Subject: [PATCH 64/74] bcl: adjust heavy clk divider ratio Bug: 314168856 Test: tbd Change-Id: If32830eb480a6db99e32b3c1a277a79f058cc43f Signed-off-by: Hiroshi Akiyama --- conf/init.gs201.rc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/conf/init.gs201.rc b/conf/init.gs201.rc index ae03ce9a..4c6da6df 100644 --- a/conf/init.gs201.rc +++ b/conf/init.gs201.rc @@ -934,13 +934,13 @@ on post-fs-data on property:vendor.brownout.mitigation.ready=1 # BCL - write /sys/devices/virtual/pmic/mitigation/clock_ratio/tpu_light_clk_ratio 0xfff041c1 #DFS - write /sys/devices/virtual/pmic/mitigation/clock_ratio/cpu1_heavy_clk_ratio 0xfff041c1 #DFS - write /sys/devices/virtual/pmic/mitigation/clock_ratio/cpu2_heavy_clk_ratio 0xfff041c1 #DFS - write /sys/devices/virtual/pmic/mitigation/clock_ratio/gpu_light_clk_ratio 0xfff041c1 #DFS + write /sys/devices/virtual/pmic/mitigation/clock_ratio/tpu_light_clk_ratio 0x80041c3 #DFS + write /sys/devices/virtual/pmic/mitigation/clock_ratio/cpu1_heavy_clk_ratio 0xfff041c0 #DFS + write /sys/devices/virtual/pmic/mitigation/clock_ratio/cpu2_heavy_clk_ratio 0xfff041c0 #DFS + write /sys/devices/virtual/pmic/mitigation/clock_ratio/gpu_light_clk_ratio 0x80041c3 #DFS write /sys/devices/virtual/pmic/mitigation/clock_ratio/cpu2_light_clk_ratio 0xfff041c3 #OCP - write /sys/devices/virtual/pmic/mitigation/clock_ratio/gpu_heavy_clk_ratio 0xfff04385 #OCP - write /sys/devices/virtual/pmic/mitigation/clock_ratio/tpu_heavy_clk_ratio 0xfff041c3 #OCP + write /sys/devices/virtual/pmic/mitigation/clock_ratio/gpu_heavy_clk_ratio 0xfff04381 #OCP + write /sys/devices/virtual/pmic/mitigation/clock_ratio/tpu_heavy_clk_ratio 0xfff041c1 #OCP write /sys/devices/virtual/pmic/mitigation/triggered_lvl/uvlo1_lvl 3200 write /sys/devices/virtual/pmic/mitigation/triggered_lvl/smpl_lvl 3100 write /sys/devices/virtual/pmic/mitigation/triggered_lvl/uvlo2_lvl 3000 From fcab3aa32fbfded0e76b60fabd0316afae2e2cd0 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:20:42 +0800 Subject: [PATCH 65/74] gs201: move bootctrl hal to gs-common Bug: 265063384 Change-Id: I11d07835c2785bdcc2a373befc1109bc12e4d11f Signed-off-by: Jason Chiu --- interfaces/boot/1.0/Android.bp | 66 --- interfaces/boot/1.0/BootControl.cpp | 272 ------------ interfaces/boot/1.0/BootControl.h | 59 --- interfaces/boot/1.0/GptUtils.cpp | 199 --------- interfaces/boot/1.0/GptUtils.h | 79 ---- ...android.hardware.boot@1.0-service-gs201.rc | 4 - interfaces/boot/1.0/service.cpp | 47 -- interfaces/boot/1.2/Android.bp | 81 ---- interfaces/boot/1.2/BootControl.cpp | 420 ------------------ interfaces/boot/1.2/BootControl.h | 69 --- interfaces/boot/1.2/DevInfo.h | 61 --- interfaces/boot/1.2/GptUtils.cpp | 193 -------- interfaces/boot/1.2/GptUtils.h | 79 ---- ...android.hardware.boot@1.2-service-gs201.rc | 7 - interfaces/boot/1.2/service.cpp | 50 --- 15 files changed, 1686 deletions(-) delete mode 100644 interfaces/boot/1.0/Android.bp delete mode 100644 interfaces/boot/1.0/BootControl.cpp delete mode 100644 interfaces/boot/1.0/BootControl.h delete mode 100644 interfaces/boot/1.0/GptUtils.cpp delete mode 100644 interfaces/boot/1.0/GptUtils.h delete mode 100644 interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc delete mode 100644 interfaces/boot/1.0/service.cpp delete mode 100644 interfaces/boot/1.2/Android.bp delete mode 100644 interfaces/boot/1.2/BootControl.cpp delete mode 100644 interfaces/boot/1.2/BootControl.h delete mode 100644 interfaces/boot/1.2/DevInfo.h delete mode 100644 interfaces/boot/1.2/GptUtils.cpp delete mode 100644 interfaces/boot/1.2/GptUtils.h delete mode 100644 interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc delete mode 100644 interfaces/boot/1.2/service.cpp diff --git a/interfaces/boot/1.0/Android.bp b/interfaces/boot/1.0/Android.bp deleted file mode 100644 index a5937e78..00000000 --- a/interfaces/boot/1.0/Android.bp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (C) 2019 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 { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/gs201:device_google_gs201_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/gs201:device_google_gs201_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.0-service-gs201", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.0-service-gs201.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} - -cc_library { - name: "android.hardware.boot@1.0-impl-gs201", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - ], -} diff --git a/interfaces/boot/1.0/BootControl.cpp b/interfaces/boot/1.0/BootControl.cpp deleted file mode 100644 index 1f155c9d..00000000 --- a/interfaces/boot/1.0/BootControl.cpp +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" -#include "GptUtils.h" - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static int setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return -1; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return -1; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return -1; - } - - e->attr |= flag; - gpt.Sync(); - - return 0; -} - -} - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - ret ? _hidl_cb({false, "Failed to set successfull flag"}) : _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = std::string("/sys/devices/platform/") + - boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char*) { - return new BootControl(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/BootControl.h b/interfaces/boot/1.0/BootControl.h deleted file mode 100644 index eb81cb07..00000000 --- a/interfaces/boot/1.0/BootControl.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::sp; - -struct BootControl : public IBootControl { - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. - -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name); - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.cpp b/interfaces/boot/1.0/GptUtils.cpp deleted file mode 100644 index f8936175..00000000 --- a/interfaces/boot/1.0/GptUtils.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) -{ - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) -{ - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) - name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e: entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) -{ - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) -{ - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - //update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() -{ - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/GptUtils.h b/interfaces/boot/1.0/GptUtils.h deleted file mode 100644 index d969d9d8..00000000 --- a/interfaces/boot/1.0/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_0 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::mapentries; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc b/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc deleted file mode 100644 index 7a7849fd..00000000 --- a/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.boot-hal-1-0 /vendor/bin/hw/android.hardware.boot@1.0-service-gs201 - class early_hal - user root - group root diff --git a/interfaces/boot/1.0/service.cpp b/interfaces/boot/1.0/service.cpp deleted file mode 100644 index 9dcd78cc..00000000 --- a/interfaces/boot/1.0/service.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ -#define LOG_TAG "android.hardware.boot@1.0-service" - -#include -#include -#include -#include -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_0::IBootControl; - -using ::android::hardware::boot::V1_0::implementation::BootControl; - -int main (int /* argc */, char * /* argv */ []) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} diff --git a/interfaces/boot/1.2/Android.bp b/interfaces/boot/1.2/Android.bp deleted file mode 100644 index a9fb7f49..00000000 --- a/interfaces/boot/1.2/Android.bp +++ /dev/null @@ -1,81 +0,0 @@ -// -// Copyright (C) 2020 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 { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "//device/google/gs201:device_google_gs201_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: [ - "//device/google/gs201:device_google_gs201_license", - ], -} - -cc_binary { - name: "android.hardware.boot@1.2-service-gs201", - defaults: ["hidl_defaults"], - relative_install_path: "hw", - vendor: true, - init_rc: ["android.hardware.boot@1.2-service-gs201.rc"], - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - "service.cpp" - ], - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} - -cc_library { - name: "android.hardware.boot@1.2-impl-gs201", - stem: "android.hardware.boot@1.0-impl-1.2-impl-gs201", - recovery: true, - srcs: [ - "BootControl.cpp", - "GptUtils.cpp", - ], - relative_install_path: "hw", - shared_libs: [ - "libbase", - "liblog", - "libhidlbase", - "libutils", - "libcutils", - "libz", - "android.hardware.boot@1.0", - "android.hardware.boot@1.1", - "android.hardware.boot@1.2", - ], - static_libs: [ - "libboot_control", - "libbootloader_message_vendor", - "libfstab", - ], -} diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp deleted file mode 100644 index a28be05a..00000000 --- a/interfaces/boot/1.2/BootControl.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (C) 2020 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. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "BootControl.h" - -#include -#include -#include -#include -#include -#include - -#include "DevInfo.h" -#include "GptUtils.h" - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using android::bootable::GetMiscVirtualAbMergeStatus; -using android::bootable::InitMiscVirtualAbMessageIfNeeded; -using android::bootable::SetMiscVirtualAbMergeStatus; -using android::hardware::boot::V1_0::BoolResult; -using android::hardware::boot::V1_0::CommandResult; -using android::hardware::boot::V1_1::MergeStatus; - -namespace { - -// clang-format off - -#define BOOT_A_PATH "/dev/block/by-name/boot_a" -#define BOOT_B_PATH "/dev/block/by-name/boot_b" -#define DEVINFO_PATH "/dev/block/by-name/devinfo" - -// slot flags -#define AB_ATTR_PRIORITY_SHIFT 52 -#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT) -#define AB_ATTR_ACTIVE_SHIFT 54 -#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT) -#define AB_ATTR_RETRY_COUNT_SHIFT (55) -#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT) -#define AB_ATTR_SUCCESSFUL (1UL << 58) -#define AB_ATTR_UNBOOTABLE (1UL << 59) - -#define AB_ATTR_MAX_PRIORITY 3UL -#define AB_ATTR_MAX_RETRY_COUNT 3UL - -// clang-format on - -static std::string getDevPath(uint32_t slot) { - char real_path[PATH_MAX]; - - const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH; - - int ret = readlink(path, real_path, sizeof real_path); - if (ret < 0) { - ALOGE("readlink failed for boot device %s\n", strerror(errno)); - return std::string(); - } - - std::string dp(real_path); - // extract /dev/sda.. part - return dp.substr(0, sizeof "/dev/block/sdX" - 1); -} - -static bool isSlotFlagSet(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - return !!(e->attr & flag); -} - -static bool setSlotFlag(uint32_t slot, uint64_t flag) { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - ALOGI("Could not get device path for slot %d\n", slot); - return false; - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - ALOGI("failed to load gpt data\n"); - return false; - } - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - if (e == nullptr) { - ALOGI("failed to get gpt entry\n"); - return false; - } - - e->attr |= flag; - gpt.Sync(); - - return true; -} - -static bool is_devinfo_valid; -static bool is_devinfo_initialized; -static std::mutex devinfo_lock; -static devinfo_t devinfo; - -static bool isDevInfoValid() { - const std::lock_guard lock(devinfo_lock); - - if (is_devinfo_initialized) { - return is_devinfo_valid; - } - - is_devinfo_initialized = true; - - android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY)); - android::base::ReadFully(fd, &devinfo, sizeof devinfo); - - if (devinfo.magic != DEVINFO_MAGIC) { - return is_devinfo_valid; - } - - uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor; - // only version 3.3+ supports A/B data - if (version >= 0x0003'0003) { - is_devinfo_valid = true; - } - - return is_devinfo_valid; -} - -static bool DevInfoSync() { - if (!isDevInfoValid()) { - return false; - } - - android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC)); - return android::base::WriteFully(fd, &devinfo, sizeof devinfo); -} - -static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) { - slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT; - slot_data.unbootable = 0; - slot_data.successful = 0; - slot_data.active = 1; - slot_data.fastboot_ok = 0; -} - -} // namespace - -// Methods from ::android::hardware::boot::V1_0::IBootControl follow. -Return BootControl::getNumberSlots() { - uint32_t slots = 0; - - if (access(BOOT_A_PATH, F_OK) == 0) - slots++; - - if (access(BOOT_B_PATH, F_OK) == 0) - slots++; - - return slots; -} - -Return BootControl::getCurrentSlot() { - char suffix[PROPERTY_VALUE_MAX]; - property_get("ro.boot.slot_suffix", suffix, "_a"); - return std::string(suffix) == "_b" ? 1 : 0; -} - -Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { - if (getNumberSlots() == 0) { - // no slots, just return true otherwise Android keeps trying - _hidl_cb({true, ""}); - return Void(); - } - - bool ret; - if (isDevInfoValid()) { - auto const slot = getCurrentSlot(); - devinfo.ab_data.slots[slot].successful = 1; - ret = DevInfoSync(); - } else { - ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL); - } - - !ret ? _hidl_cb({false, "Failed to set successful flag"}) : _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &active_slot_data = devinfo.ab_data.slots[slot]; - auto &inactive_slot_data = devinfo.ab_data.slots[!slot]; - - inactive_slot_data.active = 0; - DevInfoInitSlot(active_slot_data); - - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - if (gpt.Load()) { - _hidl_cb({false, "failed to load gpt data"}); - return Void(); - } - - gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b"); - gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a"); - if (active_entry == nullptr || inactive_entry == nullptr) { - _hidl_cb({false, "failed to get entries for boot partitions"}); - return Void(); - } - - ALOGV("slot active attributes %lx\n", active_entry->attr); - ALOGV("slot inactive attributes %lx\n", inactive_entry->attr); - - // update attributes for active and inactive - inactive_entry->attr &= ~AB_ATTR_ACTIVE; - active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) | - (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT); - } - - char boot_dev[PROPERTY_VALUE_MAX]; - property_get("ro.boot.bootdevice", boot_dev, ""); - if (boot_dev[0] == '\0') { - _hidl_cb({false, "invalid ro.boot.bootdevice prop"}); - return Void(); - } - - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled"; - int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - // Try old path for kernels < 5.4 - // TODO: remove once kernel 4.19 support is deprecated - std::string boot_lun_path = - std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled"; - fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC); - if (fd < 0) { - _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"}); - return Void(); - } - } - - // - // bBootLunEn - // 0x1 => Boot LU A = enabled, Boot LU B = disable - // 0x2 => Boot LU A = disable, Boot LU B = enabled - // - int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd); - close(fd); - if (ret < 0) { - _hidl_cb({false, "faied to write boot_lun_enabled attribute"}); - return Void(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { - if (slot >= 2) { - _hidl_cb({false, "Invalid slot"}); - return Void(); - } - - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - slot_data.unbootable = 1; - if (!DevInfoSync()) { - _hidl_cb({false, "Could not update DevInfo data"}); - return Void(); - } - } else { - std::string dev_path = getDevPath(slot); - if (dev_path.empty()) { - _hidl_cb({false, "Could not get device path for slot"}); - return Void(); - } - - GptUtils gpt(dev_path); - gpt.Load(); - - gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a"); - e->attr |= AB_ATTR_UNBOOTABLE; - - gpt.Sync(); - } - - _hidl_cb({true, ""}); - return Void(); -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) { - if (getNumberSlots() == 0) - return BoolResult::FALSE; - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool unbootable; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - unbootable = !!slot_data.unbootable; - } else { - unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE); - } - - return unbootable ? BoolResult::FALSE : BoolResult::TRUE; -} - -Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful( - uint32_t slot) { - if (getNumberSlots() == 0) { - // just return true so that we don't we another call trying to mark it as successful - // when there is no slots - return BoolResult::TRUE; - } - if (slot >= getNumberSlots()) - return BoolResult::INVALID_SLOT; - - bool successful; - if (isDevInfoValid()) { - auto &slot_data = devinfo.ab_data.slots[slot]; - successful = !!slot_data.successful; - } else { - successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL); - } - - return successful ? BoolResult::TRUE : BoolResult::FALSE; -} - -Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { - _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : ""); - return Void(); -} - -// Methods from ::android::hardware::boot::V1_1::IBootControl follow. -bool BootControl::Init() { - return InitMiscVirtualAbMessageIfNeeded(); -} - -Return BootControl::setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) { - return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status); -} - -Return<::android::hardware::boot::V1_1::MergeStatus> BootControl::getSnapshotMergeStatus() { - MergeStatus status; - if (!GetMiscVirtualAbMergeStatus(getCurrentSlot(), &status)) { - return MergeStatus::UNKNOWN; - } - return status; -} - -// Methods from ::android::hardware::boot::V1_2::IBootControl follow. -Return BootControl::getActiveBootSlot() { - if (getNumberSlots() == 0) - return 0; - - if (isDevInfoValid()) - return devinfo.ab_data.slots[1].active ? 1 : 0; - return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0; -} - -// Methods from ::android::hidl::base::V1_0::IBase follow. - -IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) { - auto module = new BootControl(); - - module->Init(); - - return module; -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h deleted file mode 100644 index 17b5f0fb..00000000 --- a/interfaces/boot/1.2/BootControl.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2020 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. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -using ::android::sp; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hardware::Return; -using ::android::hardware::Void; - -struct BootControl : public IBootControl { - bool Init(); - - // Methods from ::android::hardware::boot::V1_0::IBootControl follow. - Return getNumberSlots() override; - Return getCurrentSlot() override; - Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; - Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; - Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override; - Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful( - uint32_t slot) override; - Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; - - // Methods from ::android::hardware::boot::V1_1::IBootControl follow. - Return setSnapshotMergeStatus( - ::android::hardware::boot::V1_1::MergeStatus status) override; - Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override; - - // Methods from ::android::hardware::boot::V1_2::IBootControl follow. - Return getActiveBootSlot() override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. -}; - -// FIXME: most likely delete, this is only for passthrough implementations -extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name); - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h deleted file mode 100644 index a09a83a2..00000000 --- a/interfaces/boot/1.2/DevInfo.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ - -#pragma once - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -// -// definitions taken from ABL code -// - -constexpr uint32_t DEVINFO_MAGIC = 0x49564544; -constexpr size_t DEVINFO_AB_SLOT_COUNT = 2; - -struct devinfo_ab_slot_data_t { - uint8_t retry_count; - uint8_t unbootable : 1; - uint8_t successful : 1; - uint8_t active : 1; - uint8_t fastboot_ok : 1; - uint8_t : 4; - uint8_t unused[2]; -} __attribute__((packed)); - -typedef struct { - devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT]; -} __attribute__((packed)) devinfo_ab_data_t; - -struct devinfo_t { - uint32_t magic; - uint16_t ver_major; - uint16_t ver_minor; - uint8_t unused[40]; - devinfo_ab_data_t ab_data; - uint8_t unused1[72]; // use remaining up to complete 128 bytes -} __attribute__((packed)); - -static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size"); - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp deleted file mode 100644 index 25088e79..00000000 --- a/interfaces/boot/1.2/GptUtils.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#define LOG_TAG "bootcontrolhal" - -#include "GptUtils.h" - -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -namespace { - -static int ValidateGptHeader(gpt_header *gpt) { - if (gpt->signature != GPT_SIGNATURE) { - ALOGE("invalid gpt signature 0x%lx\n", gpt->signature); - return -1; - } - - if (gpt->header_size != sizeof(gpt_header)) { - ALOGE("invalid gpt header size %u\n", gpt->header_size); - return -1; - } - - if (gpt->entry_size != sizeof(gpt_entry)) { - ALOGE("invalid gpt entry size %u\n", gpt->entry_size); - return -1; - } - - return 0; -} - -} // namespace - -GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {} - -int GptUtils::Load(void) { - fd = open(dev_path.c_str(), O_RDWR); - if (fd < 0) { - ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno); - return -1; - } - - int ret = ioctl(fd, BLKSSZGET, &block_size); - if (ret < 0) { - ALOGE("failed to get block size %d\n", errno); - return -1; - } - - // read primary header - lseek64(fd, block_size, SEEK_SET); - ret = read(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to read gpt primary header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_primary)) { - ALOGE("error validating gpt header\n"); - return -1; - } - - // read partition entries - entry_array.resize(gpt_primary.entry_count); - uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count; - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = read(fd, entry_array.data(), entries_size); - if (ret < 0) { - ALOGE("failed to read gpt partition entries %d\n", errno); - return -1; - } - - // read gpt back header - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = read(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to read gpt backup header %d\n", errno); - return -1; - } - - if (ValidateGptHeader(&gpt_backup)) { - ALOGW("error validating gpt backup\n"); // just warn about it, not fail - } - - // Create map - auto get_name = [](const uint16_t *efi_name) { - char name[37] = {}; - for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i]; - return std::string(name); - }; - - for (auto const &e : entry_array) { - if (e.name[0] == 0) - break; // stop at the first partition with no name - std::string s = get_name(e.name); - entries[s] = const_cast(&e); - } - - return 0; -} - -gpt_entry *GptUtils::GetPartitionEntry(std::string name) { - return entries.find(name) != entries.end() ? entries[name] : nullptr; -} - -int GptUtils::Sync(void) { - if (!fd) - return -1; - - // calculate crc and check if we need to update gpt - gpt_primary.entries_crc32 = crc32(0, reinterpret_cast(entry_array.data()), - entry_array.size() * sizeof(gpt_entry)); - - // save old crc - uint32_t crc = gpt_primary.crc32; - gpt_primary.crc32 = 0; - - gpt_primary.crc32 = crc32(0, reinterpret_cast(&gpt_primary), sizeof gpt_primary); - if (crc == gpt_primary.crc32) - return 0; // nothing to do (no changes) - - ALOGI("updating GPT\n"); - - lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET); - int ret = write(fd, &gpt_primary, sizeof gpt_primary); - if (ret < 0) { - ALOGE("failed to write gpt primary header %d\n", errno); - return -1; - } - - lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt partition entries %d\n", errno); - return -1; - } - - // update GPT backup entries and backup - lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET); - ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry)); - if (ret < 0) { - ALOGE("failed to write gpt backup partition entries %d\n", errno); - return -1; - } - - gpt_backup.entries_crc32 = gpt_primary.entries_crc32; - gpt_backup.crc32 = 0; - gpt_backup.crc32 = crc32(0, reinterpret_cast(&gpt_backup), sizeof gpt_backup); - lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET); - ret = write(fd, &gpt_backup, sizeof gpt_backup); - if (ret < 0) { - ALOGE("failed to write gpt backup header %d\n", errno); - return -1; - } - - fsync(fd); - - return 0; -} - -GptUtils::~GptUtils() { - if (fd) { - Sync(); - close(fd); - } -} - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h deleted file mode 100644 index a2bed334..00000000 --- a/interfaces/boot/1.2/GptUtils.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2019 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. - */ - -#pragma once - -#include -#include -#include - -namespace android { -namespace hardware { -namespace boot { -namespace V1_2 { -namespace implementation { - -#define GPT_SIGNATURE 0x5452415020494645UL - -typedef struct { - uint8_t type_guid[16]; - uint8_t guid[16]; - uint64_t first_lba; - uint64_t last_lba; - uint64_t attr; - uint16_t name[36]; -} __attribute__((packed)) gpt_entry; - -typedef struct { - uint64_t signature; - uint32_t revision; - uint32_t header_size; - uint32_t crc32; - uint32_t reserved; - uint64_t current_lba; - uint64_t backup_lba; - uint64_t first_usable_lba; - uint64_t last_usable_lba; - uint8_t disk_guid[16]; - uint64_t start_lba; - uint32_t entry_count; - uint32_t entry_size; - uint32_t entries_crc32; -} __attribute__((packed)) gpt_header; - -class GptUtils { - public: - GptUtils(const std::string dev_path); - int Load(void); - gpt_entry *GetPartitionEntry(std::string name); - int Sync(void); - ~GptUtils(); - - private: - std::string dev_path; - int fd; - uint32_t block_size; - gpt_header gpt_primary; - gpt_header gpt_backup; - std::vector entry_array; - std::map entries; -}; - -} // namespace implementation -} // namespace V1_2 -} // namespace boot -} // namespace hardware -} // namespace android diff --git a/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc b/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc deleted file mode 100644 index 3457b5f0..00000000 --- a/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.boot-hal-1-2 /vendor/bin/hw/android.hardware.boot@1.2-service-gs201 - interface android.hardware.boot@1.0::IBootControl default - interface android.hardware.boot@1.1::IBootControl default - interface android.hardware.boot@1.2::IBootControl default - class early_hal - user root - group root diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp deleted file mode 100644 index f07682e9..00000000 --- a/interfaces/boot/1.2/service.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2020 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. - */ - -#define LOG_TAG "android.hardware.boot@1.2-service" - -#include -#include -#include -#include - -#include "BootControl.h" - -using ::android::status_t; - -using ::android::hardware::boot::V1_2::IBootControl; - -using ::android::hardware::boot::V1_2::implementation::BootControl; -// using ::android::hardware::boot::implementation::BootControl; - -int main(int /* argc */, char * /* argv */[]) { - // This function must be called before you join to ensure the proper - // number of threads are created. The threadpool will never exceed - // size one because of this call. - ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/); - - ::android::sp bootctrl = new BootControl(); - const status_t status = bootctrl->registerAsService(); - if (status != ::android::OK) { - return 1; // or handle error - } - - // Adds this thread to the threadpool, resulting in one total - // thread in the threadpool. We could also do other things, but - // would have to specify 'false' to willJoin in configureRpcThreadpool. - ::android::hardware::joinRpcThreadpool(); - return 1; // joinRpcThreadpool should never return -} From 2baf1d63eb96e34fff54b6a8ad50dcaeeed14a88 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Mon, 27 Nov 2023 17:27:55 +0800 Subject: [PATCH 66/74] gs201: move bootctrl service declaration to gs-common Bug: 265063384 Change-Id: If265211d9b433eef789d0d68df1cae7cc369cfa1 --- device.mk | 5 ----- 1 file changed, 5 deletions(-) diff --git a/device.mk b/device.mk index 4342a53a..41cb5c04 100644 --- a/device.mk +++ b/device.mk @@ -922,11 +922,6 @@ PRODUCT_PACKAGES_DEBUG += \ PRODUCT_PACKAGES += ShannonRcs endif -# Boot Control HAL -PRODUCT_PACKAGES += \ - android.hardware.boot@1.2-impl-gs201 \ - android.hardware.boot@1.2-service-gs201 - # Exynos RIL and telephony # Multi SIM(DSDS) SIM_COUNT := 2 From ca538bb2b4c3d3b812c266773ce7494163c8c975 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 9 Nov 2023 21:25:52 +0800 Subject: [PATCH 67/74] gs201: include bootctrl_hidl_1.2.mk from gs-common Bug: 265063384 Change-Id: I2e00ddafe970dcda873da691bd64908f5ef1c0f9 Signed-off-by: Jason Chiu --- device.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/device.mk b/device.mk index 41cb5c04..68bd8793 100644 --- a/device.mk +++ b/device.mk @@ -36,6 +36,7 @@ include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk include device/google/gs-common/gyotaku_app/gyotaku.mk +include device/google/gs-common/bootctrl/bootctrl_hidl_1.2.mk TARGET_BOARD_PLATFORM := gs201 From a9ac5d5869eb22c1e99f81161b711cdf6c7c6270 Mon Sep 17 00:00:00 2001 From: Qian-Hao Huang Date: Tue, 5 Dec 2023 09:36:02 +0000 Subject: [PATCH 68/74] Revert "usb: introduce UsbDataSessionMonitor class" Revert submission 25524752-usbDataSessionMonitor Reason for revert: Test for gs101/gs201 boot blocking issue (b/314904288) Reverted changes: /q/submissionid:25524752-usbDataSessionMonitor Change-Id: I0f762a9ba8345d2963ebfb2d50cb8a7460885221 --- usb/usb/Android.bp | 1 - usb/usb/Usb.cpp | 308 +++++++++++++++++----- usb/usb/Usb.h | 34 ++- usb/usb/UsbDataSessionMonitor.cpp | 420 ------------------------------ usb/usb/UsbDataSessionMonitor.h | 114 -------- 5 files changed, 279 insertions(+), 598 deletions(-) delete mode 100644 usb/usb/UsbDataSessionMonitor.cpp delete mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 609af179..8fd373b2 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,7 +34,6 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", - "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 555e6576..224951a1 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include +#include #include #include @@ -55,6 +57,9 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; using android::String8; using android::Vector; @@ -90,22 +95,17 @@ constexpr char kThermalZoneForTempReadSecondary2[] = "qi_therm"; constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_active"; constexpr char KPogoMoveDataToUsb[] = "/sys/devices/platform/google,pogo/move_data_to_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; -constexpr char kUdcUeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; -constexpr char kUdcStatePath[] = - "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -constexpr char kHost1UeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; -constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; -constexpr char kHost2UeventRegex[] = - "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb3/3-0:1.0"; -constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb3/3-0:1.0/usb3-port1/state"; -constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; +constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +// xhci-hcd-exynos and usb device numbering could vary on different platforms +constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus); +#define USB_STATE_MAX_LEN 20 #define CTRL_TRANSFER_TIMEOUT_MSEC 1000 #define GL852G_VENDOR_ID 0x05e3 #define GL852G_PRODUCT_ID1 0x0608 @@ -538,20 +538,11 @@ void *usbHostWork(void *param) { return NULL; } -void updatePortStatus(android::hardware::usb::Usb *usb) { - std::vector currentPortStatus; - - queryVersionHelper(usb, ¤tPortStatus); -} - Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), - mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, - kHost2UeventRegex, kHost2StatePath, kDataRolePath, - std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -931,18 +922,6 @@ done: return Status::ERROR; } -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - std::vector warnings; - - usb->mUsbDataSessionMonitor.getComplianceWarnings( - (*currentPortStatus)[0].currentDataRole, &warnings); - (*currentPortStatus)[0].complianceWarnings.insert( - (*currentPortStatus)[0].complianceWarnings.end(), - warnings.begin(), - warnings.end()); -} - void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1038,17 +1017,194 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -struct data { - int uevent_fd; - ::aidl::android::hardware::usb::Usb *usb; -}; +void report_usb_data_session_event(android::hardware::usb::Usb *usb) { + std::vector events; -static void uevent_event(uint32_t /*epevents*/, struct data *payload) { + if (usb->mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &usb->mDeviceState.states, + &usb->mDeviceState.timestamps, &event); + events.push_back(event); + } else if (usb->mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto &entry : usb->mHostStateMap) { + // Host port will at least get an not_attached event after enablement, + // skip upload if no additional state is added. + if (entry.second.states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, &entry.second.states, + &entry.second.timestamps, &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty && usb->mHostStateMap.size() > 0) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), + usb->mDataSessionStart, + &usb->mHostStateMap.begin()->second.states, + &usb->mHostStateMap.begin()->second.timestamps, + &event); + events.push_back(event); + } + } else { + return; + } + + const shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + +static void unregisterEpollEntry(Usb *usb, std::string name) { + std::map *map; + int fd; + + map = &usb->mEpollEntries; + auto it = map->find(name); + if (it != map->end()) { + ALOGI("epoll unregister %s", name.c_str()); + fd = it->second.payload.fd; + epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); + close(fd); + map->erase(it); + } +} + +static void unregisterEpollEntries(Usb *usb) { + std::map *map; + std::string name; + + map = &usb->mEpollEntries; + for (auto it = map->begin(); it != map->end();) { + name = it->first; + it++; + unregisterEpollEntry(usb, name); + } +} + +static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + std::map *map; + struct Usb::epollEntry *entry; + struct epoll_event ev; + + map = &usb->mEpollEntries; + if (map->find(name) != map->end()) { + ALOGE("%s already registered", name.c_str()); + unregisterEpollEntry(usb, name); + } + + entry = &(*map)[name]; + entry->payload.fd = fd; + entry->payload.name = name; + entry->payload.usb = usb; + entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); + + ev.events = flags; + ev.data.ptr = (void *)&entry->cb; + + if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + unregisterEpollEntry(usb, name); + return -1; + } + + ALOGI("epoll register %s", name.c_str()); + + return 0; +} + +static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, + void (*func)(uint32_t, struct Usb::payload*)) { + int fd; + + fd = open(name.c_str(), O_RDONLY); + if (fd < 0) { + ALOGE("Cannot open %s", name.c_str()); + return -1; + } + + return registerEpollEntry(usb, name, fd, flags, func); +} + +static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { + device->states.clear(); + device->timestamps.clear(); + device->portResetCount = 0; +} + +static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { + ALOGI("Update USB device state: %s", state); + + device->states.push_back(state); + device->timestamps.push_back(std::chrono::steady_clock::now()); + + if (!std::strcmp(state, "configured\n")) { + device->portResetCount = 0; + } else if (!std::strcmp(state, "default\n")) { + device->portResetCount++; + } +} + +static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + struct Usb::usbDeviceState *device; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); +} + +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; + PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; + + if (newDataRole != usb->mDataRole) { + // Upload metrics for the last non-powerbrick data session that has ended + if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { + report_usb_data_session_event(usb); + } + + // Set up for the new data session + usb->mDataRole = newDataRole; + usb->mDataSessionStart = std::chrono::steady_clock::now(); + usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); + if (newDataRole == PortDataRole::DEVICE) { + clearUsbDeviceState(&usb->mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + for (auto &entry : usb->mHostStateMap) { + clearUsbDeviceState(&entry.second); + } + } + } + + // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data + // session when BC1.2 SDP times out and falls back to DCP + if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { + usb->mIsPowerBrickConnected = true; + } +} + +static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; + std::cmatch match; - n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1094,6 +1250,28 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } else if (!strncmp(cp, kOverheatStatsDev, strlen(kOverheatStatsDev))) { ALOGV("Overheat Cooling device suez update"); report_overheat_event(payload->usb); + } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { + /* + * Matched strings: + * 1st: entire string + * 2nd: uevent action, either "bind" or "unbind" + * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto + * 4th: usb device number, e.g. 1 for usb1 + * + * The strings are used to composed usb device state path, e.g. + * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state + */ + if (match.size() == 4) { + std::string action = match[1].str(); + std::string id = match[3].str(); + std::string path = "/sys" + match[2].str() + "usb" + id + "/" + + id + "-0:1.0/usb" + id + "-port1/state"; + if (action == "bind") { + registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); + } else if (action == "unbind") { + unregisterEpollEntry(payload->usb, path); + } + } } /* advance to after the next \0 */ while (*cp++) { @@ -1101,37 +1279,46 @@ static void uevent_event(uint32_t /*epevents*/, struct data *payload) { } } +static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(payload->fd, 0, SEEK_SET); + n = read(payload->fd, &state, USB_STATE_MAX_LEN); + + updateUsbDeviceState(&payload->usb->mDeviceState, state); +} + void *work(void *param) { int epoll_fd, uevent_fd; - struct epoll_event ev; int nevents = 0; - struct data payload; + Usb *usb = (Usb *)param; ALOGE("creating thread"); - uevent_fd = uevent_open_socket(64 * 1024, true); - - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed\n"); - return NULL; - } - - payload.uevent_fd = uevent_fd; - payload.usb = (::aidl::android::hardware::usb::Usb *)param; - - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - ev.events = EPOLLIN; - ev.data.ptr = (void *)uevent_event; - epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); + return NULL; + } + usb->mEpollFd = epoll_fd; + + // Monitor uevent + uevent_fd = uevent_open_socket(64 * 1024, true); + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed"); + goto error; + } + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { + ALOGE("failed to monitor uevent"); goto error; } - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { - ALOGE("epoll_ctl failed; errno=%d", errno); + // Monitor udc state + if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { + ALOGE("failed to monitor udc state"); goto error; } @@ -1148,14 +1335,15 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, - &payload); + (*(std::function*)events[n].data.ptr)(events[n].events); } } ALOGI("exiting worker thread"); error: - close(uevent_fd); + unregisterEpollEntries(usb); + + usb->mEpollFd = -1; if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 495a467f..83bae889 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,9 +19,9 @@ #include #include #include +#include #include #include -#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -88,8 +88,6 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; - // Report usb data session event and data incompliance warnings - UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -100,6 +98,36 @@ struct Usb : public BnUsb { int mUsbHubVendorCmdValue; int mUsbHubVendorCmdIndex; + // USB device state monitoring + struct usbDeviceState { + // Usb device state raw strings read from sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + int portResetCount; + }; + struct usbDeviceState mDeviceState; + // Map host device path name to usbDeviceState + std::map mHostStateMap; + // Cache relevant info for USB data session metrics collection when a session starts, including + // the data role, power brick status and the time when the session starts. + PortDataRole mDataRole; + bool mIsPowerBrickConnected; + std::chrono::steady_clock::time_point mDataSessionStart; + + // File monitoring through epoll + int mEpollFd; + struct payload { + int fd; + std::string name; + Usb *usb; + }; + struct epollEntry { + struct payload payload; + std::function cb; + }; + std::map mEpollEntries; + private: pthread_t mPoll; pthread_t mUsbHost; diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp deleted file mode 100644 index 77defb30..00000000 --- a/usb/usb/UsbDataSessionMonitor.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (C) 2023 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. - */ - -#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" - -#include "UsbDataSessionMonitor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace usb_flags = android::hardware::usb::flags; - -using aidl::android::frameworks::stats::IStats; -using android::base::ReadFileToString; -using android::hardware::google::pixel::getStatsService; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::usb::addEpollFd; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -#define UEVENT_MSG_LEN 2048 -#define USB_STATE_MAX_LEN 20 -#define DATA_ROLE_MAX_LEN 10 - -constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; -constexpr char kNotAttachedState[] = "not attached\n"; -constexpr char kAttachedState[] = "attached\n"; -constexpr char kPoweredState[] = "powered\n"; -constexpr char kDefaultState[] = "default\n"; -constexpr char kAddressedState[] = "addressed\n"; -constexpr char kConfiguredState[] = "configured\n"; -constexpr char kSuspendedState[] = "suspended\n"; -const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, - kDefaultState, kAddressedState, kConfiguredState, - kSuspendedState}; - -static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - struct epoll_event ev; - - unique_fd fd(open(filePath.c_str(), O_RDONLY)); - - if (fd.get() == -1) { - ALOGI("Cannot open %s", filePath.c_str()); - return -1; - } - - ev.data.fd = fd.get(); - ev.events = EPOLLPRI; - - if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - return -1; - } - - fileFd = std::move(fd); - ALOGI("epoll registered %s", filePath.c_str()); - return 0; -} - -static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { - epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); - fileFd.release(); - - ALOGI("epoll unregistered %s", filePath.c_str()); -} - -UsbDataSessionMonitor::UsbDataSessionMonitor( - const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, std::function updatePortStatusCb) { - struct epoll_event ev; - std::string udc; - - unique_fd epollFd(epoll_create(8)); - if (epollFd.get() == -1) { - ALOGE("epoll_create failed; errno=%d", errno); - abort(); - } - - unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); - if (ueventFd.get() == -1) { - ALOGE("uevent_open_socket failed"); - abort(); - } - fcntl(ueventFd, F_SETFL, O_NONBLOCK); - - if (addEpollFd(epollFd, ueventFd)) - abort(); - - if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { - ALOGE("monitor data role failed"); - abort(); - } - - /* - * The device state file could be absent depending on the current data role - * and driver architecture. It's ok for addEpollFile to fail here, the file - * will be monitored later when its presence is detected by uevent. - */ - mDeviceState.filePath = deviceStatePath; - mDeviceState.ueventRegex = deviceUeventRegex; - addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); - - mHost1State.filePath = host1StatePath; - mHost1State.ueventRegex = host1UeventRegex; - addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); - - mHost2State.filePath = host2StatePath; - mHost2State.ueventRegex = host2UeventRegex; - addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); - - mEpollFd = std::move(epollFd); - mUeventFd = std::move(ueventFd); - mUpdatePortStatusCb = updatePortStatusCb; - - if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) - mUdcBind = true; - else - mUdcBind = false; - - if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { - ALOGE("pthread creation failed %d", errno); - abort(); - } -} - -UsbDataSessionMonitor::~UsbDataSessionMonitor() {} - -void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { - std::vector events; - - if (mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, - &mDeviceState.states, &mDeviceState.timestamps, &event); - events.push_back(event); - } else if (mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto e : {&mHost1State, &mHost2State}) { - /* - * Host port will at least get an not_attached event after enablement, - * skip upload if no additional state is added. - */ - if (e->states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), - mDataSessionStart, &e->states, &e->timestamps, - &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, - &mHost1State.states, &mHost1State.timestamps, &event); - events.push_back(event); - } - } else { - return; - } - - const std::shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - -void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, - std::vector *warnings) { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (role != mDataRole || role == PortDataRole::NONE) - return; - - for (auto w : mWarningSet) { - warnings->push_back(w); - } -} - -void UsbDataSessionMonitor::notifyComplianceWarning() { - if (!usb_flags::enable_report_usb_data_compliance_warning()) - return; - - if (mUpdatePortStatusCb) - mUpdatePortStatusCb(); -} - -void UsbDataSessionMonitor::evaluateComplianceWarning() { - std::set newWarningSet; - - // TODO: add heuristics and update newWarningSet - if (mDataRole == PortDataRole::DEVICE && mUdcBind) { - } else if (mDataRole == PortDataRole::HOST) { - } - - if (newWarningSet != mWarningSet) { - mWarningSet = newWarningSet; - notifyComplianceWarning(); - } -} - -void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { - deviceState->states.clear(); - deviceState->timestamps.clear(); -} - -void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(deviceState->fd.get(), 0, SEEK_SET); - n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); - - if (kValidStates.find(state) == kValidStates.end()) { - ALOGE("Invalid state %s", state); - return; - } - - ALOGI("Update USB device state: %s", state); - - deviceState->states.push_back(state); - deviceState->timestamps.push_back(boot_clock::now()); - evaluateComplianceWarning(); -} - -void UsbDataSessionMonitor::handleDataRoleEvent() { - int n; - PortDataRole newDataRole; - char role[DATA_ROLE_MAX_LEN] = {0}; - - lseek(mDataRoleFd.get(), 0, SEEK_SET); - n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); - - ALOGI("Update USB data role %s", role); - - if (!std::strcmp(role, "host")) { - newDataRole = PortDataRole::HOST; - } else if (!std::strcmp(role, "device")) { - newDataRole = PortDataRole::DEVICE; - } else { - newDataRole = PortDataRole::NONE; - } - - if (newDataRole != mDataRole) { - // Upload metrics for the last data session that has ended - if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { - reportUsbDataSessionMetrics(); - } - - // Set up for the new data session - mWarningSet.clear(); - mDataRole = newDataRole; - mDataSessionStart = boot_clock::now(); - - if (newDataRole == PortDataRole::DEVICE) { - clearDeviceStateEvents(&mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - clearDeviceStateEvents(&mHost1State); - clearDeviceStateEvents(&mHost2State); - } - } -} - -void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { - std::string function; - bool newUdcBind; - - /* - * /sys/class/udc//function prints out name of currently running USB gadget driver - * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc - * Empty name string means the udc device is not bound and gadget is pulldown. - */ - if (!ReadFileToString("/sys" + devname + "/function", &function)) - return; - - if (function == "") - newUdcBind = false; - else - newUdcBind = true; - - if (newUdcBind == mUdcBind) - return; - - if (mDataRole == PortDataRole::DEVICE) { - if (mUdcBind && !newUdcBind) { - /* - * Gadget soft pulldown: report metrics as the end of a data session and - * re-evaluate compliance warnings to clear existing warnings if any. - */ - reportUsbDataSessionMetrics(); - evaluateComplianceWarning(); - - } else if (!mUdcBind && newUdcBind) { - // Gadget soft pullup: reset and start accounting for a new data session. - clearDeviceStateEvents(&mDeviceState); - mDataSessionStart = boot_clock::now(); - } - } - - ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); - mUdcBind = newUdcBind; -} - -void UsbDataSessionMonitor::handleUevent() { - char msg[UEVENT_MSG_LEN + 2]; - char *cp; - int n; - - n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); - if (n <= 0) - return; - if (n >= UEVENT_MSG_LEN) - return; - - msg[n] = '\0'; - msg[n + 1] = '\0'; - cp = msg; - - while (*cp) { - for (auto e : {&mHost1State, &mHost2State}) { - if (std::regex_search(cp, std::regex(e->ueventRegex))) { - if (!strncmp(cp, "bind@", strlen("bind@"))) { - addEpollFile(mEpollFd.get(), e->filePath, e->fd); - } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { - removeEpollFile(mEpollFd.get(), e->filePath, e->fd); - } - } - } - - // TODO: support bind@ unbind@ to detect dynamically allocated udc device - if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { - if (!strncmp(cp, "change@", strlen("change@"))) { - char *devname = cp + strlen("change@"); - /* - * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. - * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually - * executed. Add a short delay to get the correct state while working on a fix - * upstream. - */ - usleep(50000); - updateUdcBindStatus(devname); - } - } - /* advance to after the next \0 */ - while (*cp++) { - } - } -} - -void *UsbDataSessionMonitor::monitorThread(void *param) { - UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; - struct epoll_event events[64]; - int nevents = 0; - - while (true) { - nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); - if (nevents == -1) { - if (errno == EINTR) - continue; - ALOGE("usb epoll_wait failed; errno=%d", errno); - break; - } - - for (int n = 0; n < nevents; ++n) { - if (events[n].data.fd == monitor->mUeventFd.get()) { - monitor->handleUevent(); - } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { - monitor->handleDataRoleEvent(); - } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mDeviceState); - } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost1State); - } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { - monitor->handleDeviceStateEvent(&monitor->mHost2State); - } - } - } - return NULL; -} - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h deleted file mode 100644 index 596f378f..00000000 --- a/usb/usb/UsbDataSessionMonitor.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2023 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. - */ - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -namespace aidl { -namespace android { -namespace hardware { -namespace usb { - -using ::aidl::android::hardware::usb::ComplianceWarning; -using ::aidl::android::hardware::usb::PortDataRole; -using ::android::base::boot_clock; -using ::android::base::unique_fd; - -/* - * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices - * including device mode (udc), host mode high-speed port and host mode super-speed port. It - * reports Suez metrics for each data session and also provides API to query the compliance - * warnings detected in the current usb data session. - */ -class UsbDataSessionMonitor { - public: - /* - * The host mode high-speed port and super-speed port can be assigned to either host1 or - * host2 without affecting functionality. - * - * UeventRegex: name regex of the device that's being monitored. The regex is matched against - * uevent to detect dynamic creation/deletion/change of the device. - * StatePath: usb device state sysfs path of the device, monitored by epoll. - * dataRolePath: path to the usb data role sysfs, monitored by epoll. - * updatePortStatusCb: the callback is invoked when the compliance warings changes. - */ - UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, - const std::string &host1UeventRegex, const std::string &host1StatePath, - const std::string &host2UeventRegex, const std::string &host2StatePath, - const std::string &dataRolePath, - std::function updatePortStatusCb); - ~UsbDataSessionMonitor(); - // Returns the compliance warnings detected in the current data session. - void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); - - private: - struct usbDeviceState { - unique_fd fd; - std::string filePath; - std::string ueventRegex; - // Usb device states reported by state sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - }; - - static void *monitorThread(void *param); - void handleUevent(); - void handleDataRoleEvent(); - void handleDeviceStateEvent(struct usbDeviceState *deviceState); - void clearDeviceStateEvents(struct usbDeviceState *deviceState); - void reportUsbDataSessionMetrics(); - void evaluateComplianceWarning(); - void notifyComplianceWarning(); - void updateUdcBindStatus(const std::string &devname); - - pthread_t mMonitor; - unique_fd mEpollFd; - unique_fd mUeventFd; - unique_fd mDataRoleFd; - struct usbDeviceState mDeviceState; - struct usbDeviceState mHost1State; - struct usbDeviceState mHost2State; - std::set mWarningSet; - // Callback function to notify the caller when there's a change in compliance warnings. - std::function mUpdatePortStatusCb; - /* - * Cache relevant info for a USB data session when one starts, including - * the data role and the time when the session starts. - */ - PortDataRole mDataRole; - boot_clock::time_point mDataSessionStart; - /* - * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which - * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, - * the gadget is in soft pulldown state and is expected not to enumerate. During gadget - * function switch, the udc device usually go through unbind and bind. - */ - bool mUdcBind; -}; - -} // namespace usb -} // namespace hardware -} // namespace android -} // namespace aidl From dc7845e89af802793b7a76dfb34e48636b2a1086 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 1 Dec 2023 11:36:08 +0800 Subject: [PATCH 69/74] gs201: update manifest HAL android.hardware.boot from hidl 1.2 to aidl Bug: 314215524 Change-Id: I59988d13f9bedc3a2067f9ffc49d690048383d66 Signed-off-by: Jason Chiu --- manifest-gralloc3.xml | 5 ++--- manifest.xml | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/manifest-gralloc3.xml b/manifest-gralloc3.xml index 82ff14ab..cd405200 100644 --- a/manifest-gralloc3.xml +++ b/manifest-gralloc3.xml @@ -68,10 +68,9 @@ default - + android.hardware.boot - hwbinder - @1.2::IBootControl/default + IBootControl/default android.hardware.sensors diff --git a/manifest.xml b/manifest.xml index 031b46f3..a5cf98dc 100644 --- a/manifest.xml +++ b/manifest.xml @@ -8,10 +8,9 @@ default - + android.hardware.boot - hwbinder - @1.2::IBootControl/default + IBootControl/default com.google.input From a509a4b067ffe877dfed0e360c581edb89edd3e0 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 1 Dec 2023 11:37:20 +0800 Subject: [PATCH 70/74] gs201: use android.hardware.boot aidl interface Bug: 314215524 Change-Id: Id6e4083674e8e42572952ea516eae244d4d5e8e7 Signed-off-by: Jason Chiu --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 68bd8793..fd91d880 100644 --- a/device.mk +++ b/device.mk @@ -36,7 +36,7 @@ include device/google/gs-common/widevine/widevine.mk include device/google/gs-common/sota_app/factoryota.mk include device/google/gs-common/misc_writer/misc_writer.mk include device/google/gs-common/gyotaku_app/gyotaku.mk -include device/google/gs-common/bootctrl/bootctrl_hidl_1.2.mk +include device/google/gs-common/bootctrl/bootctrl_aidl.mk TARGET_BOARD_PLATFORM := gs201 From 8d10e34fe05fc31b0604bad062424404f91cfbab Mon Sep 17 00:00:00 2001 From: Roy Luo Date: Fri, 8 Dec 2023 15:35:14 +0000 Subject: [PATCH 71/74] Revert^2 "usb: introduce UsbDataSessionMonitor class" a9ac5d5869eb22c1e99f81161b711cdf6c7c6270 Bug: 297224564 Bug: 296119135 Change-Id: I0e15924ff133c8070c923f9072497bfda4370b5b --- usb/usb/Android.bp | 1 + usb/usb/Usb.cpp | 308 +++++----------------- usb/usb/Usb.h | 34 +-- usb/usb/UsbDataSessionMonitor.cpp | 420 ++++++++++++++++++++++++++++++ usb/usb/UsbDataSessionMonitor.h | 114 ++++++++ 5 files changed, 598 insertions(+), 279 deletions(-) create mode 100644 usb/usb/UsbDataSessionMonitor.cpp create mode 100644 usb/usb/UsbDataSessionMonitor.h diff --git a/usb/usb/Android.bp b/usb/usb/Android.bp index 8fd373b2..609af179 100644 --- a/usb/usb/Android.bp +++ b/usb/usb/Android.bp @@ -34,6 +34,7 @@ cc_binary { srcs: [ "service.cpp", "Usb.cpp", + "UsbDataSessionMonitor.cpp", ], shared_libs: [ "libbase", diff --git a/usb/usb/Usb.cpp b/usb/usb/Usb.cpp index 224951a1..555e6576 100644 --- a/usb/usb/Usb.cpp +++ b/usb/usb/Usb.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,6 @@ #include #include -#include #include #include @@ -57,9 +55,6 @@ using android::base::Trim; using android::hardware::google::pixel::getStatsService; using android::hardware::google::pixel::PixelAtoms::VendorUsbPortOverheat; using android::hardware::google::pixel::reportUsbPortOverheat; -using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; -using android::hardware::google::pixel::reportUsbDataSessionEvent; -using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; using android::String8; using android::Vector; @@ -95,17 +90,22 @@ constexpr char kThermalZoneForTempReadSecondary2[] = "qi_therm"; constexpr char kPogoUsbActive[] = "/sys/devices/platform/google,pogo/pogo_usb_active"; constexpr char KPogoMoveDataToUsb[] = "/sys/devices/platform/google,pogo/move_data_to_usb"; constexpr char kPowerSupplyUsbType[] = "/sys/class/power_supply/usb/usb_type"; -constexpr char kUdcState[] = "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; -// xhci-hcd-exynos and usb device numbering could vary on different platforms -constexpr char kHostUeventRegex[] = "^(bind|unbind)@(/devices/platform/11210000\\.usb/11210000\\.dwc3/xhci-hcd-exynos\\.[0-9]\\.auto/)usb([0-9])/[0-9]-0:1\\.0"; +constexpr char kUdcUeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3"; +constexpr char kUdcStatePath[] = + "/sys/devices/platform/11210000.usb/11210000.dwc3/udc/11210000.dwc3/state"; +constexpr char kHost1UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb2/2-0:1.0"; +constexpr char kHost1StatePath[] = "/sys/bus/usb/devices/usb2/2-0:1.0/usb2-port1/state"; +constexpr char kHost2UeventRegex[] = + "/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.[0-9].auto/usb3/3-0:1.0"; +constexpr char kHost2StatePath[] = "/sys/bus/usb/devices/usb3/3-0:1.0/usb3-port1/state"; +constexpr char kDataRolePath[] = "/sys/devices/platform/11210000.usb/new_data_role"; constexpr int kSamplingIntervalSec = 5; void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus); -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus); -#define USB_STATE_MAX_LEN 20 #define CTRL_TRANSFER_TIMEOUT_MSEC 1000 #define GL852G_VENDOR_ID 0x05e3 #define GL852G_PRODUCT_ID1 0x0608 @@ -538,11 +538,20 @@ void *usbHostWork(void *param) { return NULL; } +void updatePortStatus(android::hardware::usb::Usb *usb) { + std::vector currentPortStatus; + + queryVersionHelper(usb, ¤tPortStatus); +} + Usb::Usb() : mLock(PTHREAD_MUTEX_INITIALIZER), mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER), mPartnerLock(PTHREAD_MUTEX_INITIALIZER), mPartnerUp(false), + mUsbDataSessionMonitor(kUdcUeventRegex, kUdcStatePath, kHost1UeventRegex, kHost1StatePath, + kHost2UeventRegex, kHost2StatePath, kDataRolePath, + std::bind(&updatePortStatus, this)), mOverheat(ZoneInfo(TemperatureType::USB_PORT, kThermalZoneForTrip, ThrottlingSeverity::CRITICAL), {ZoneInfo(TemperatureType::UNKNOWN, kThermalZoneForTempReadPrimary, @@ -922,6 +931,18 @@ done: return Status::ERROR; } +void queryUsbDataSession(android::hardware::usb::Usb *usb, + std::vector *currentPortStatus) { + std::vector warnings; + + usb->mUsbDataSessionMonitor.getComplianceWarnings( + (*currentPortStatus)[0].currentDataRole, &warnings); + (*currentPortStatus)[0].complianceWarnings.insert( + (*currentPortStatus)[0].complianceWarnings.end(), + warnings.begin(), + warnings.end()); +} + void queryVersionHelper(android::hardware::usb::Usb *usb, std::vector *currentPortStatus) { Status status; @@ -1017,194 +1038,17 @@ void report_overheat_event(android::hardware::usb::Usb *usb) { } } -void report_usb_data_session_event(android::hardware::usb::Usb *usb) { - std::vector events; +struct data { + int uevent_fd; + ::aidl::android::hardware::usb::Usb *usb; +}; - if (usb->mDataRole == PortDataRole::DEVICE) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(false /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &usb->mDeviceState.states, - &usb->mDeviceState.timestamps, &event); - events.push_back(event); - } else if (usb->mDataRole == PortDataRole::HOST) { - bool empty = true; - for (auto &entry : usb->mHostStateMap) { - // Host port will at least get an not_attached event after enablement, - // skip upload if no additional state is added. - if (entry.second.states.size() > 1) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, &entry.second.states, - &entry.second.timestamps, &event); - events.push_back(event); - empty = false; - } - } - // All host ports have no state update, upload an event to reflect it - if (empty && usb->mHostStateMap.size() > 0) { - VendorUsbDataSessionEvent event; - BuildVendorUsbDataSessionEvent(true /* is_host */, std::chrono::steady_clock::now(), - usb->mDataSessionStart, - &usb->mHostStateMap.begin()->second.states, - &usb->mHostStateMap.begin()->second.timestamps, - &event); - events.push_back(event); - } - } else { - return; - } - - const shared_ptr stats_client = getStatsService(); - if (!stats_client) { - ALOGE("Unable to get AIDL Stats service"); - return; - } - - for (auto &event : events) { - reportUsbDataSessionEvent(stats_client, event); - } -} - -static void unregisterEpollEntry(Usb *usb, std::string name) { - std::map *map; - int fd; - - map = &usb->mEpollEntries; - auto it = map->find(name); - if (it != map->end()) { - ALOGI("epoll unregister %s", name.c_str()); - fd = it->second.payload.fd; - epoll_ctl(usb->mEpollFd, EPOLL_CTL_DEL, fd, NULL); - close(fd); - map->erase(it); - } -} - -static void unregisterEpollEntries(Usb *usb) { - std::map *map; - std::string name; - - map = &usb->mEpollEntries; - for (auto it = map->begin(); it != map->end();) { - name = it->first; - it++; - unregisterEpollEntry(usb, name); - } -} - -static int registerEpollEntry(Usb *usb, std::string name, int fd, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - std::map *map; - struct Usb::epollEntry *entry; - struct epoll_event ev; - - map = &usb->mEpollEntries; - if (map->find(name) != map->end()) { - ALOGE("%s already registered", name.c_str()); - unregisterEpollEntry(usb, name); - } - - entry = &(*map)[name]; - entry->payload.fd = fd; - entry->payload.name = name; - entry->payload.usb = usb; - entry->cb = std::bind(func, std::placeholders::_1, &entry->payload); - - ev.events = flags; - ev.data.ptr = (void *)&entry->cb; - - if (epoll_ctl(usb->mEpollFd, EPOLL_CTL_ADD, fd, &ev) != 0) { - ALOGE("epoll_ctl failed; errno=%d", errno); - unregisterEpollEntry(usb, name); - return -1; - } - - ALOGI("epoll register %s", name.c_str()); - - return 0; -} - -static int registerEpollEntryByFile(Usb *usb, std::string name, int flags, - void (*func)(uint32_t, struct Usb::payload*)) { - int fd; - - fd = open(name.c_str(), O_RDONLY); - if (fd < 0) { - ALOGE("Cannot open %s", name.c_str()); - return -1; - } - - return registerEpollEntry(usb, name, fd, flags, func); -} - -static void clearUsbDeviceState(struct Usb::usbDeviceState *device) { - device->states.clear(); - device->timestamps.clear(); - device->portResetCount = 0; -} - -static void updateUsbDeviceState(struct Usb::usbDeviceState *device, char *state) { - ALOGI("Update USB device state: %s", state); - - device->states.push_back(state); - device->timestamps.push_back(std::chrono::steady_clock::now()); - - if (!std::strcmp(state, "configured\n")) { - device->portResetCount = 0; - } else if (!std::strcmp(state, "default\n")) { - device->portResetCount++; - } -} - -static void host_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - struct Usb::usbDeviceState *device; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mHostStateMap[payload->name], state); -} - -void queryUsbDataSession(android::hardware::usb::Usb *usb, - std::vector *currentPortStatus) { - PortDataRole newDataRole = (*currentPortStatus)[0].currentDataRole; - PowerBrickStatus newPowerBrickStatus = (*currentPortStatus)[0].powerBrickStatus; - - if (newDataRole != usb->mDataRole) { - // Upload metrics for the last non-powerbrick data session that has ended - if (usb->mDataRole != PortDataRole::NONE && !usb->mIsPowerBrickConnected) { - report_usb_data_session_event(usb); - } - - // Set up for the new data session - usb->mDataRole = newDataRole; - usb->mDataSessionStart = std::chrono::steady_clock::now(); - usb->mIsPowerBrickConnected = (newPowerBrickStatus == PowerBrickStatus::CONNECTED); - if (newDataRole == PortDataRole::DEVICE) { - clearUsbDeviceState(&usb->mDeviceState); - } else if (newDataRole == PortDataRole::HOST) { - for (auto &entry : usb->mHostStateMap) { - clearUsbDeviceState(&entry.second); - } - } - } - - // PowerBrickStatus could flip from DISCONNECTED to CONNECTED during the same data - // session when BC1.2 SDP times out and falls back to DCP - if (newPowerBrickStatus == PowerBrickStatus::CONNECTED) { - usb->mIsPowerBrickConnected = true; - } -} - -static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { +static void uevent_event(uint32_t /*epevents*/, struct data *payload) { char msg[UEVENT_MSG_LEN + 2]; char *cp; int n; - std::cmatch match; - n = uevent_kernel_multicast_recv(payload->fd, msg, UEVENT_MSG_LEN); + n = uevent_kernel_multicast_recv(payload->uevent_fd, msg, UEVENT_MSG_LEN); if (n <= 0) return; if (n >= UEVENT_MSG_LEN) /* overflow -- discard */ @@ -1250,28 +1094,6 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } else if (!strncmp(cp, kOverheatStatsDev, strlen(kOverheatStatsDev))) { ALOGV("Overheat Cooling device suez update"); report_overheat_event(payload->usb); - } else if (std::regex_match(cp, match, std::regex(kHostUeventRegex))) { - /* - * Matched strings: - * 1st: entire string - * 2nd: uevent action, either "bind" or "unbind" - * 3rd: xhci device path, e.g. devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto - * 4th: usb device number, e.g. 1 for usb1 - * - * The strings are used to composed usb device state path, e.g. - * /sys/devices/platform/11210000.usb/11210000.dwc3/xhci-hcd-exynos.4.auto/usb2/2-0:1.0/usb2-port1/state - */ - if (match.size() == 4) { - std::string action = match[1].str(); - std::string id = match[3].str(); - std::string path = "/sys" + match[2].str() + "usb" + id + "/" + - id + "-0:1.0/usb" + id + "-port1/state"; - if (action == "bind") { - registerEpollEntryByFile(payload->usb, path, EPOLLPRI, host_event); - } else if (action == "unbind") { - unregisterEpollEntry(payload->usb, path); - } - } } /* advance to after the next \0 */ while (*cp++) { @@ -1279,46 +1101,37 @@ static void uevent_event(uint32_t /*epevents*/, struct Usb::payload *payload) { } } -static void udc_event(uint32_t /*epevents*/, struct Usb::payload *payload) { - int n; - char state[USB_STATE_MAX_LEN] = {0}; - - lseek(payload->fd, 0, SEEK_SET); - n = read(payload->fd, &state, USB_STATE_MAX_LEN); - - updateUsbDeviceState(&payload->usb->mDeviceState, state); -} - void *work(void *param) { int epoll_fd, uevent_fd; + struct epoll_event ev; int nevents = 0; - Usb *usb = (Usb *)param; + struct data payload; ALOGE("creating thread"); + uevent_fd = uevent_open_socket(64 * 1024, true); + + if (uevent_fd < 0) { + ALOGE("uevent_init: uevent_open_socket failed\n"); + return NULL; + } + + payload.uevent_fd = uevent_fd; + payload.usb = (::aidl::android::hardware::usb::Usb *)param; + + fcntl(uevent_fd, F_SETFL, O_NONBLOCK); + + ev.events = EPOLLIN; + ev.data.ptr = (void *)uevent_event; + epoll_fd = epoll_create(64); if (epoll_fd == -1) { ALOGE("epoll_create failed; errno=%d", errno); - return NULL; - } - usb->mEpollFd = epoll_fd; - - // Monitor uevent - uevent_fd = uevent_open_socket(64 * 1024, true); - if (uevent_fd < 0) { - ALOGE("uevent_init: uevent_open_socket failed"); - goto error; - } - fcntl(uevent_fd, F_SETFL, O_NONBLOCK); - - if (registerEpollEntry(usb, "uevent", uevent_fd, EPOLLIN, uevent_event)) { - ALOGE("failed to monitor uevent"); goto error; } - // Monitor udc state - if (registerEpollEntryByFile(usb, kUdcState, EPOLLPRI, udc_event)) { - ALOGE("failed to monitor udc state"); + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, uevent_fd, &ev) == -1) { + ALOGE("epoll_ctl failed; errno=%d", errno); goto error; } @@ -1335,15 +1148,14 @@ void *work(void *param) { for (int n = 0; n < nevents; ++n) { if (events[n].data.ptr) - (*(std::function*)events[n].data.ptr)(events[n].events); + (*(void (*)(int, struct data *payload))events[n].data.ptr)(events[n].events, + &payload); } } ALOGI("exiting worker thread"); error: - unregisterEpollEntries(usb); - - usb->mEpollFd = -1; + close(uevent_fd); if (epoll_fd >= 0) close(epoll_fd); diff --git a/usb/usb/Usb.h b/usb/usb/Usb.h index 83bae889..495a467f 100644 --- a/usb/usb/Usb.h +++ b/usb/usb/Usb.h @@ -19,9 +19,9 @@ #include #include #include -#include #include #include +#include #define UEVENT_MSG_LEN 2048 // The type-c stack waits for 4.5 - 5.5 secs before declaring a port non-pd. @@ -88,6 +88,8 @@ struct Usb : public BnUsb { // Variable to signal partner coming back online after type switch bool mPartnerUp; + // Report usb data session event and data incompliance warnings + UsbDataSessionMonitor mUsbDataSessionMonitor; // Usb Overheat object for push suez event UsbOverheatEvent mOverheat; // Temperature when connected @@ -98,36 +100,6 @@ struct Usb : public BnUsb { int mUsbHubVendorCmdValue; int mUsbHubVendorCmdIndex; - // USB device state monitoring - struct usbDeviceState { - // Usb device state raw strings read from sysfs - std::vector states; - // Timestamps of when the usb device states were captured - std::vector timestamps; - int portResetCount; - }; - struct usbDeviceState mDeviceState; - // Map host device path name to usbDeviceState - std::map mHostStateMap; - // Cache relevant info for USB data session metrics collection when a session starts, including - // the data role, power brick status and the time when the session starts. - PortDataRole mDataRole; - bool mIsPowerBrickConnected; - std::chrono::steady_clock::time_point mDataSessionStart; - - // File monitoring through epoll - int mEpollFd; - struct payload { - int fd; - std::string name; - Usb *usb; - }; - struct epollEntry { - struct payload payload; - std::function cb; - }; - std::map mEpollEntries; - private: pthread_t mPoll; pthread_t mUsbHost; diff --git a/usb/usb/UsbDataSessionMonitor.cpp b/usb/usb/UsbDataSessionMonitor.cpp new file mode 100644 index 00000000..77defb30 --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (C) 2023 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. + */ + +#define LOG_TAG "android.hardware.usb.aidl-service.UsbDataSessionMonitor" + +#include "UsbDataSessionMonitor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace usb_flags = android::hardware::usb::flags; + +using aidl::android::frameworks::stats::IStats; +using android::base::ReadFileToString; +using android::hardware::google::pixel::getStatsService; +using android::hardware::google::pixel::reportUsbDataSessionEvent; +using android::hardware::google::pixel::PixelAtoms::VendorUsbDataSessionEvent; +using android::hardware::google::pixel::usb::addEpollFd; +using android::hardware::google::pixel::usb::BuildVendorUsbDataSessionEvent; + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +#define UEVENT_MSG_LEN 2048 +#define USB_STATE_MAX_LEN 20 +#define DATA_ROLE_MAX_LEN 10 + +constexpr char kUdcConfigfsPath[] = "/config/usb_gadget/g1/UDC"; +constexpr char kNotAttachedState[] = "not attached\n"; +constexpr char kAttachedState[] = "attached\n"; +constexpr char kPoweredState[] = "powered\n"; +constexpr char kDefaultState[] = "default\n"; +constexpr char kAddressedState[] = "addressed\n"; +constexpr char kConfiguredState[] = "configured\n"; +constexpr char kSuspendedState[] = "suspended\n"; +const std::set kValidStates = {kNotAttachedState, kAttachedState, kPoweredState, + kDefaultState, kAddressedState, kConfiguredState, + kSuspendedState}; + +static int addEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + struct epoll_event ev; + + unique_fd fd(open(filePath.c_str(), O_RDONLY)); + + if (fd.get() == -1) { + ALOGI("Cannot open %s", filePath.c_str()); + return -1; + } + + ev.data.fd = fd.get(); + ev.events = EPOLLPRI; + + if (epoll_ctl(epollFd, EPOLL_CTL_ADD, fd.get(), &ev) != 0) { + ALOGE("epoll_ctl failed; errno=%d", errno); + return -1; + } + + fileFd = std::move(fd); + ALOGI("epoll registered %s", filePath.c_str()); + return 0; +} + +static void removeEpollFile(const int &epollFd, const std::string &filePath, unique_fd &fileFd) { + epoll_ctl(epollFd, EPOLL_CTL_DEL, fileFd.get(), NULL); + fileFd.release(); + + ALOGI("epoll unregistered %s", filePath.c_str()); +} + +UsbDataSessionMonitor::UsbDataSessionMonitor( + const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, std::function updatePortStatusCb) { + struct epoll_event ev; + std::string udc; + + unique_fd epollFd(epoll_create(8)); + if (epollFd.get() == -1) { + ALOGE("epoll_create failed; errno=%d", errno); + abort(); + } + + unique_fd ueventFd(uevent_open_socket(64 * 1024, true)); + if (ueventFd.get() == -1) { + ALOGE("uevent_open_socket failed"); + abort(); + } + fcntl(ueventFd, F_SETFL, O_NONBLOCK); + + if (addEpollFd(epollFd, ueventFd)) + abort(); + + if (addEpollFile(epollFd.get(), dataRolePath, mDataRoleFd) != 0) { + ALOGE("monitor data role failed"); + abort(); + } + + /* + * The device state file could be absent depending on the current data role + * and driver architecture. It's ok for addEpollFile to fail here, the file + * will be monitored later when its presence is detected by uevent. + */ + mDeviceState.filePath = deviceStatePath; + mDeviceState.ueventRegex = deviceUeventRegex; + addEpollFile(epollFd.get(), mDeviceState.filePath, mDeviceState.fd); + + mHost1State.filePath = host1StatePath; + mHost1State.ueventRegex = host1UeventRegex; + addEpollFile(epollFd.get(), mHost1State.filePath, mHost1State.fd); + + mHost2State.filePath = host2StatePath; + mHost2State.ueventRegex = host2UeventRegex; + addEpollFile(epollFd.get(), mHost2State.filePath, mHost2State.fd); + + mEpollFd = std::move(epollFd); + mUeventFd = std::move(ueventFd); + mUpdatePortStatusCb = updatePortStatusCb; + + if (ReadFileToString(kUdcConfigfsPath, &udc) && !udc.empty()) + mUdcBind = true; + else + mUdcBind = false; + + if (pthread_create(&mMonitor, NULL, this->monitorThread, this)) { + ALOGE("pthread creation failed %d", errno); + abort(); + } +} + +UsbDataSessionMonitor::~UsbDataSessionMonitor() {} + +void UsbDataSessionMonitor::reportUsbDataSessionMetrics() { + std::vector events; + + if (mDataRole == PortDataRole::DEVICE) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(false /* is_host */, boot_clock::now(), mDataSessionStart, + &mDeviceState.states, &mDeviceState.timestamps, &event); + events.push_back(event); + } else if (mDataRole == PortDataRole::HOST) { + bool empty = true; + for (auto e : {&mHost1State, &mHost2State}) { + /* + * Host port will at least get an not_attached event after enablement, + * skip upload if no additional state is added. + */ + if (e->states.size() > 1) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), + mDataSessionStart, &e->states, &e->timestamps, + &event); + events.push_back(event); + empty = false; + } + } + // All host ports have no state update, upload an event to reflect it + if (empty) { + VendorUsbDataSessionEvent event; + BuildVendorUsbDataSessionEvent(true /* is_host */, boot_clock::now(), mDataSessionStart, + &mHost1State.states, &mHost1State.timestamps, &event); + events.push_back(event); + } + } else { + return; + } + + const std::shared_ptr stats_client = getStatsService(); + if (!stats_client) { + ALOGE("Unable to get AIDL Stats service"); + return; + } + + for (auto &event : events) { + reportUsbDataSessionEvent(stats_client, event); + } +} + +void UsbDataSessionMonitor::getComplianceWarnings(const PortDataRole &role, + std::vector *warnings) { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (role != mDataRole || role == PortDataRole::NONE) + return; + + for (auto w : mWarningSet) { + warnings->push_back(w); + } +} + +void UsbDataSessionMonitor::notifyComplianceWarning() { + if (!usb_flags::enable_report_usb_data_compliance_warning()) + return; + + if (mUpdatePortStatusCb) + mUpdatePortStatusCb(); +} + +void UsbDataSessionMonitor::evaluateComplianceWarning() { + std::set newWarningSet; + + // TODO: add heuristics and update newWarningSet + if (mDataRole == PortDataRole::DEVICE && mUdcBind) { + } else if (mDataRole == PortDataRole::HOST) { + } + + if (newWarningSet != mWarningSet) { + mWarningSet = newWarningSet; + notifyComplianceWarning(); + } +} + +void UsbDataSessionMonitor::clearDeviceStateEvents(struct usbDeviceState *deviceState) { + deviceState->states.clear(); + deviceState->timestamps.clear(); +} + +void UsbDataSessionMonitor::handleDeviceStateEvent(struct usbDeviceState *deviceState) { + int n; + char state[USB_STATE_MAX_LEN] = {0}; + + lseek(deviceState->fd.get(), 0, SEEK_SET); + n = read(deviceState->fd.get(), &state, USB_STATE_MAX_LEN); + + if (kValidStates.find(state) == kValidStates.end()) { + ALOGE("Invalid state %s", state); + return; + } + + ALOGI("Update USB device state: %s", state); + + deviceState->states.push_back(state); + deviceState->timestamps.push_back(boot_clock::now()); + evaluateComplianceWarning(); +} + +void UsbDataSessionMonitor::handleDataRoleEvent() { + int n; + PortDataRole newDataRole; + char role[DATA_ROLE_MAX_LEN] = {0}; + + lseek(mDataRoleFd.get(), 0, SEEK_SET); + n = read(mDataRoleFd.get(), &role, DATA_ROLE_MAX_LEN); + + ALOGI("Update USB data role %s", role); + + if (!std::strcmp(role, "host")) { + newDataRole = PortDataRole::HOST; + } else if (!std::strcmp(role, "device")) { + newDataRole = PortDataRole::DEVICE; + } else { + newDataRole = PortDataRole::NONE; + } + + if (newDataRole != mDataRole) { + // Upload metrics for the last data session that has ended + if (mDataRole == PortDataRole::HOST || (mDataRole == PortDataRole::DEVICE && mUdcBind)) { + reportUsbDataSessionMetrics(); + } + + // Set up for the new data session + mWarningSet.clear(); + mDataRole = newDataRole; + mDataSessionStart = boot_clock::now(); + + if (newDataRole == PortDataRole::DEVICE) { + clearDeviceStateEvents(&mDeviceState); + } else if (newDataRole == PortDataRole::HOST) { + clearDeviceStateEvents(&mHost1State); + clearDeviceStateEvents(&mHost2State); + } + } +} + +void UsbDataSessionMonitor::updateUdcBindStatus(const std::string &devname) { + std::string function; + bool newUdcBind; + + /* + * /sys/class/udc//function prints out name of currently running USB gadget driver + * Ref: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-udc + * Empty name string means the udc device is not bound and gadget is pulldown. + */ + if (!ReadFileToString("/sys" + devname + "/function", &function)) + return; + + if (function == "") + newUdcBind = false; + else + newUdcBind = true; + + if (newUdcBind == mUdcBind) + return; + + if (mDataRole == PortDataRole::DEVICE) { + if (mUdcBind && !newUdcBind) { + /* + * Gadget soft pulldown: report metrics as the end of a data session and + * re-evaluate compliance warnings to clear existing warnings if any. + */ + reportUsbDataSessionMetrics(); + evaluateComplianceWarning(); + + } else if (!mUdcBind && newUdcBind) { + // Gadget soft pullup: reset and start accounting for a new data session. + clearDeviceStateEvents(&mDeviceState); + mDataSessionStart = boot_clock::now(); + } + } + + ALOGI("Udc bind status changes from %b to %b", mUdcBind, newUdcBind); + mUdcBind = newUdcBind; +} + +void UsbDataSessionMonitor::handleUevent() { + char msg[UEVENT_MSG_LEN + 2]; + char *cp; + int n; + + n = uevent_kernel_multicast_recv(mUeventFd.get(), msg, UEVENT_MSG_LEN); + if (n <= 0) + return; + if (n >= UEVENT_MSG_LEN) + return; + + msg[n] = '\0'; + msg[n + 1] = '\0'; + cp = msg; + + while (*cp) { + for (auto e : {&mHost1State, &mHost2State}) { + if (std::regex_search(cp, std::regex(e->ueventRegex))) { + if (!strncmp(cp, "bind@", strlen("bind@"))) { + addEpollFile(mEpollFd.get(), e->filePath, e->fd); + } else if (!strncmp(cp, "unbind@", strlen("unbind@"))) { + removeEpollFile(mEpollFd.get(), e->filePath, e->fd); + } + } + } + + // TODO: support bind@ unbind@ to detect dynamically allocated udc device + if (std::regex_search(cp, std::regex(mDeviceState.ueventRegex))) { + if (!strncmp(cp, "change@", strlen("change@"))) { + char *devname = cp + strlen("change@"); + /* + * Udc device emits a KOBJ_CHANGE event on configfs driver bind and unbind. + * TODO: upstream udc driver emits KOBJ_CHANGE event BEFORE unbind is actually + * executed. Add a short delay to get the correct state while working on a fix + * upstream. + */ + usleep(50000); + updateUdcBindStatus(devname); + } + } + /* advance to after the next \0 */ + while (*cp++) { + } + } +} + +void *UsbDataSessionMonitor::monitorThread(void *param) { + UsbDataSessionMonitor *monitor = (UsbDataSessionMonitor *)param; + struct epoll_event events[64]; + int nevents = 0; + + while (true) { + nevents = epoll_wait(monitor->mEpollFd.get(), events, 64, -1); + if (nevents == -1) { + if (errno == EINTR) + continue; + ALOGE("usb epoll_wait failed; errno=%d", errno); + break; + } + + for (int n = 0; n < nevents; ++n) { + if (events[n].data.fd == monitor->mUeventFd.get()) { + monitor->handleUevent(); + } else if (events[n].data.fd == monitor->mDataRoleFd.get()) { + monitor->handleDataRoleEvent(); + } else if (events[n].data.fd == monitor->mDeviceState.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mDeviceState); + } else if (events[n].data.fd == monitor->mHost1State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost1State); + } else if (events[n].data.fd == monitor->mHost2State.fd.get()) { + monitor->handleDeviceStateEvent(&monitor->mHost2State); + } + } + } + return NULL; +} + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/usb/usb/UsbDataSessionMonitor.h b/usb/usb/UsbDataSessionMonitor.h new file mode 100644 index 00000000..596f378f --- /dev/null +++ b/usb/usb/UsbDataSessionMonitor.h @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2023 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. + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +namespace aidl { +namespace android { +namespace hardware { +namespace usb { + +using ::aidl::android::hardware::usb::ComplianceWarning; +using ::aidl::android::hardware::usb::PortDataRole; +using ::android::base::boot_clock; +using ::android::base::unique_fd; + +/* + * UsbDataSessionMonitor monitors the usb device state sysfs of 3 different usb devices + * including device mode (udc), host mode high-speed port and host mode super-speed port. It + * reports Suez metrics for each data session and also provides API to query the compliance + * warnings detected in the current usb data session. + */ +class UsbDataSessionMonitor { + public: + /* + * The host mode high-speed port and super-speed port can be assigned to either host1 or + * host2 without affecting functionality. + * + * UeventRegex: name regex of the device that's being monitored. The regex is matched against + * uevent to detect dynamic creation/deletion/change of the device. + * StatePath: usb device state sysfs path of the device, monitored by epoll. + * dataRolePath: path to the usb data role sysfs, monitored by epoll. + * updatePortStatusCb: the callback is invoked when the compliance warings changes. + */ + UsbDataSessionMonitor(const std::string &deviceUeventRegex, const std::string &deviceStatePath, + const std::string &host1UeventRegex, const std::string &host1StatePath, + const std::string &host2UeventRegex, const std::string &host2StatePath, + const std::string &dataRolePath, + std::function updatePortStatusCb); + ~UsbDataSessionMonitor(); + // Returns the compliance warnings detected in the current data session. + void getComplianceWarnings(const PortDataRole &role, std::vector *warnings); + + private: + struct usbDeviceState { + unique_fd fd; + std::string filePath; + std::string ueventRegex; + // Usb device states reported by state sysfs + std::vector states; + // Timestamps of when the usb device states were captured + std::vector timestamps; + }; + + static void *monitorThread(void *param); + void handleUevent(); + void handleDataRoleEvent(); + void handleDeviceStateEvent(struct usbDeviceState *deviceState); + void clearDeviceStateEvents(struct usbDeviceState *deviceState); + void reportUsbDataSessionMetrics(); + void evaluateComplianceWarning(); + void notifyComplianceWarning(); + void updateUdcBindStatus(const std::string &devname); + + pthread_t mMonitor; + unique_fd mEpollFd; + unique_fd mUeventFd; + unique_fd mDataRoleFd; + struct usbDeviceState mDeviceState; + struct usbDeviceState mHost1State; + struct usbDeviceState mHost2State; + std::set mWarningSet; + // Callback function to notify the caller when there's a change in compliance warnings. + std::function mUpdatePortStatusCb; + /* + * Cache relevant info for a USB data session when one starts, including + * the data role and the time when the session starts. + */ + PortDataRole mDataRole; + boot_clock::time_point mDataSessionStart; + /* + * In gadget mode: this indicates whether the udc device is bound to the configfs driver, which + * is done by userspace writing the udc device name to /config/usb_gadget/g1/UDC. When unbound, + * the gadget is in soft pulldown state and is expected not to enumerate. During gadget + * function switch, the udc device usually go through unbind and bind. + */ + bool mUdcBind; +}; + +} // namespace usb +} // namespace hardware +} // namespace android +} // namespace aidl From 8dbc173f2bf04255ce22dd1e13e888050aad36ca Mon Sep 17 00:00:00 2001 From: Hungyen Weng Date: Mon, 11 Dec 2023 11:22:13 -0800 Subject: [PATCH 72/74] config: Use carrier config in ROM by default Bug: 314890118 Test: Flash ROM and confirm the carrier config follows the ROM. Change-Id: Id0407802e2027397ca7a409345c51273b75079e7 --- device.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device.mk b/device.mk index 91364b02..fedeaf5d 100644 --- a/device.mk +++ b/device.mk @@ -190,7 +190,7 @@ PRODUCT_PRODUCT_PROPERTIES += \ # Carrier configuration default location PRODUCT_PROPERTY_OVERRIDES += \ - persist.vendor.radio.config.carrier_config_dir=/mnt/vendor/modem_img/images/default/confpack + persist.vendor.radio.config.carrier_config_dir=/vendor/firmware/carrierconfig PRODUCT_PROPERTY_OVERRIDES += \ telephony.active_modems.max_count=2 From 2ae9b5a025b08fce2af5fecac1fd935cc6dbb1f3 Mon Sep 17 00:00:00 2001 From: Poomarin Phloyphisut Date: Fri, 6 Oct 2023 03:11:22 +0000 Subject: [PATCH 73/74] pixelstats: Fix access permission by adding total call count and update cca path sysfs Related changes : ag/24513108 Bug: 289857250 Test: Local test uploading atoms. Change-Id: I584af796d03585ba3e27baeb8d006af2cab8c24d --- pixelstats/service.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pixelstats/service.cpp b/pixelstats/service.cpp index 5d739b18..ab6f85f2 100644 --- a/pixelstats/service.cpp +++ b/pixelstats/service.cpp @@ -71,7 +71,7 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { "/sys/devices/platform/100b0000.TPU/trip_counter", "/sys/devices/platform/100b0000.AUR/trip_counter", }, - .CCARatePath = "/sys/devices/platform/audiometrics/cca_rate_read_once", + .CCARatePath = "/sys/devices/platform/audiometrics/cca_count_read_once", .TempResidencyAndResetPaths = { { "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats", @@ -88,7 +88,8 @@ const struct SysfsCollector::SysfsPaths sysfs_paths = { .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset", .ModemPcieLinkStatsPath = "/sys/devices/platform/11920000.pcie/link_stats", .WifiPcieLinkStatsPath = "/sys/devices/platform/14520000.pcie/link_stats", - .GMSRPath = "/sys/class/power_supply/maxfg/gmsr" + .GMSRPath = "/sys/class/power_supply/maxfg/gmsr", + .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count" }; const struct UeventListener::UeventPaths ueventPaths = { From 84128834583cb62308d1daddc3ebb1fbc538cce2 Mon Sep 17 00:00:00 2001 From: Kuen-Han Tsai Date: Tue, 12 Dec 2023 13:39:21 +0800 Subject: [PATCH 74/74] usb: enable media-presence polling for SD cards After USB enumeration, some SD card readers do not send signals to the device when the SD card is inserted or removed. To support SD card hotplugging, this patch enables in-kernel media-presence polling, which will check the SD card status every 2 seconds after a SD card reader is attached. Bug: 186479576 Test: SD card insertion/removal and data copy (see b/301566595) Change-Id: Ibd7816b717d2fbcb038a7c0ff703b7fab7d2a46c Signed-off-by: Kuen-Han Tsai --- conf/init.gs201.usb.rc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/init.gs201.usb.rc b/conf/init.gs201.usb.rc index 6a52fb07..9ba9eb8a 100644 --- a/conf/init.gs201.usb.rc +++ b/conf/init.gs201.usb.rc @@ -371,6 +371,8 @@ on boot write sys/module/usbcore/parameters/initial_descriptor_timeout 500 # Use USB Gadget HAL setprop sys.usb.configfs 2 + # Enable in-kernel media-presence polling for SD cards + write /sys/module/block/parameters/events_dfl_poll_msecs 2000 on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1 write /config/usb_gadget/g1/idProduct 0x4EE7