aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-25 03:03:07 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-03-25 03:03:07 +0000
commitfcd729c4f98c3adebb31a133635e3cfef95cb9eb (patch)
tree060dbd21fa475645b3a0684bcfeadffa4f2a4175
parent83beea2b5b57051d624cbf71426d0af03b40b5a8 (diff)
parentb5b3cb74e5f37c7a0b55735ca9e07fc21fcf88a3 (diff)
downloadgs-common-fcd729c4f98c3adebb31a133635e3cfef95cb9eb.tar.gz
Snap for 9815702 from b5b3cb74e5f37c7a0b55735ca9e07fc21fcf88a3 to udc-release
Change-Id: Ic1b32b959db61683cbe581de7393ba4e53438f5c
-rw-r--r--battery_mitigation/Android.bp4
-rw-r--r--battery_mitigation/battery_mitigation.cpp3
-rw-r--r--gear/dumpstate/Android.bp29
-rw-r--r--gear/dumpstate/Dumpstate.cpp215
-rw-r--r--gear/dumpstate/Dumpstate.h53
-rw-r--r--gear/dumpstate/aidl.mk3
-rw-r--r--gear/dumpstate/android.hardware.dumpstate-service.rc5
-rw-r--r--gear/dumpstate/android.hardware.dumpstate-service.xml9
-rw-r--r--gear/dumpstate/sepolicy/file.te5
-rw-r--r--gear/dumpstate/sepolicy/file_contexts4
-rw-r--r--gear/dumpstate/sepolicy/hal_dumpstate_default.te5
-rw-r--r--gear/dumpstate/service.cpp37
12 files changed, 370 insertions, 2 deletions
diff --git a/battery_mitigation/Android.bp b/battery_mitigation/Android.bp
index 3c0b882..c919de5 100644
--- a/battery_mitigation/Android.bp
+++ b/battery_mitigation/Android.bp
@@ -36,10 +36,10 @@ cc_binary {
"libbinder_ndk",
"libcutils",
"libhardware",
- "libhidlbase",
"liblog",
"libutils",
- "android.hardware.thermal@2.0"
+ "android.hardware.thermal@2.0",
+ "android.hardware.thermal-V1-ndk"
],
srcs: [
"battery_mitigation.cpp",
diff --git a/battery_mitigation/battery_mitigation.cpp b/battery_mitigation/battery_mitigation.cpp
index a7c1fd4..230f297 100644
--- a/battery_mitigation/battery_mitigation.cpp
+++ b/battery_mitigation/battery_mitigation.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "battery-mitigation"
#include <battery_mitigation/BatteryMitigation.h>
+#include <android/binder_process.h>
using android::hardware::google::pixel::BatteryMitigation;
using android::hardware::google::pixel::MitigationConfig;
@@ -73,6 +74,8 @@ const std::regex kTimestampRegex("^\\S+\\s[0-9]+:[0-9]+:[0-9]+\\S+$");
int main(int /*argc*/, char ** /*argv*/) {
auto batteryMitigationStartTime = std::chrono::system_clock::now();
+ ABinderProcess_setThreadPoolMaxThreadCount(1);
+ ABinderProcess_startThreadPool();
bmSp = new BatteryMitigation(cfg);
if (!bmSp) {
return 0;
diff --git a/gear/dumpstate/Android.bp b/gear/dumpstate/Android.bp
new file mode 100644
index 0000000..590ba10
--- /dev/null
+++ b/gear/dumpstate/Android.bp
@@ -0,0 +1,29 @@
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+cc_binary {
+ name: "android.hardware.dumpstate-service",
+ srcs: [
+ "Dumpstate.cpp",
+ "service.cpp",
+ ],
+ init_rc: ["android.hardware.dumpstate-service.rc"],
+ vintf_fragments: ["android.hardware.dumpstate-service.xml"],
+ cflags: [
+ "-Wall",
+ "-Werror",
+ ],
+ shared_libs: [
+ "libbase",
+ "libbinder_ndk",
+ "libcutils",
+ "libdumpstateutil",
+ "liblog",
+ "libutils",
+ "libdump",
+ "android.hardware.dumpstate-V1-ndk",
+ ],
+ vendor: true,
+ relative_install_path: "hw",
+}
diff --git a/gear/dumpstate/Dumpstate.cpp b/gear/dumpstate/Dumpstate.cpp
new file mode 100644
index 0000000..1e4d982
--- /dev/null
+++ b/gear/dumpstate/Dumpstate.cpp
@@ -0,0 +1,215 @@
+/*
+ * Copyright 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 "dumpstate_device"
+
+#include <inttypes.h>
+
+#include <android-base/file.h>
+#include <android-base/stringprintf.h>
+#include <android-base/properties.h>
+#include <android-base/unique_fd.h>
+#include <log/log.h>
+#include <sys/stat.h>
+#include <dump/pixel_dump.h>
+#include "Dumpstate.h"
+
+#include "DumpstateUtil.h"
+
+#define HW_REVISION "ro.boot.hardware.revision"
+
+using android::os::dumpstate::CommandOptions;
+using android::os::dumpstate::DumpFileToFd;
+using android::os::dumpstate::PropertiesHelper;
+using android::os::dumpstate::RunCommandToFd;
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace dumpstate {
+
+typedef std::chrono::time_point<std::chrono::steady_clock> timepoint_t;
+
+const char kVerboseLoggingProperty[] = "persist.vendor.verbose_logging_enabled";
+
+timepoint_t startSection(int fd, const std::string &sectionName) {
+ ::android::base::WriteStringToFd(
+ "\n"
+ "------ Section start: " + sectionName + " ------\n"
+ "\n", fd);
+ return std::chrono::steady_clock::now();
+}
+
+void endSection(int fd, const std::string &sectionName, timepoint_t startTime) {
+ auto endTime = std::chrono::steady_clock::now();
+ auto elapsedMsec = std::chrono::duration_cast<std::chrono::milliseconds>
+ (endTime - startTime).count();
+
+ ::android::base::WriteStringToFd(
+ "\n"
+ "------ Section end: " + sectionName + " ------\n"
+ "Elapsed msec: " + std::to_string(elapsedMsec) + "\n"
+ "\n", fd);
+}
+
+// Dump data requested by an argument to the "dump" interface, or help info
+// if the specified section is not supported.
+void Dumpstate::dumpTextSection(int fd, const std::string &sectionName) {
+ bool dumpAll = (sectionName == kAllSections);
+ std::string dumpFiles;
+
+ // Execute all or designated programs under vendor/bin/dump/
+ std::unique_ptr<DIR, decltype(&closedir)> dir(opendir("/vendor/bin/dump"), closedir);
+ if (!dir) {
+ ALOGE("Fail To Open Dir vendor/bin/dump/");
+ ::android::base::WriteStringToFd("Fail To Open Dir vendor/bin/dump/\n", fd);
+ return;
+ }
+ dirent *entry;
+ while ((entry = readdir(dir.get())) != nullptr) {
+ // Skip '.', '..'
+ if (entry->d_name[0] == '.') {
+ continue;
+ }
+ std::string bin(entry->d_name);
+ dumpFiles = dumpFiles + " " + bin;
+ if (dumpAll || sectionName == bin) {
+ auto startTime = startSection(fd, bin);
+ RunCommandToFd(fd, "/vendor/bin/dump/"+bin, {"/vendor/bin/dump/"+bin}, CommandOptions::WithTimeout(15).Build());
+ endSection(fd, bin, startTime);
+ if (!dumpAll) {
+ return;
+ }
+ }
+ }
+
+ if (dumpAll) {
+ RunCommandToFd(fd, "VENDOR PROPERTIES", {"/vendor/bin/getprop"});
+ return;
+ }
+
+ // An unsupported section was requested on the command line
+ ::android::base::WriteStringToFd("Unrecognized text section: " + sectionName + "\n", fd);
+ ::android::base::WriteStringToFd("Try \"" + kAllSections + "\" or one of the following:", fd);
+ ::android::base::WriteStringToFd(dumpFiles, fd);
+ ::android::base::WriteStringToFd("\nNote: sections with attachments (e.g. dump_soc) are"
+ "not available from the command line.\n", fd);
+}
+
+void Dumpstate::dumpLogSection(int fd, int fd_bin)
+{
+ std::string logDir = MODEM_LOG_DIRECTORY;
+ const std::string logCombined = logDir + "/combined_logs.tar";
+ const std::string logAllDir = logDir + "/all_logs";
+
+ RunCommandToFd(fd, "MKDIR LOG", {"/vendor/bin/mkdir", "-p", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
+
+ dumpTextSection(fd, kAllSections);
+
+ 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());
+
+ std::vector<uint8_t> buffer(65536);
+ ::android::base::unique_fd fdLog(TEMP_FAILURE_RETRY(open(logCombined.c_str(), O_RDONLY | O_CLOEXEC | O_NONBLOCK)));
+
+ if (fdLog >= 0) {
+ while (1) {
+ ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fdLog, buffer.data(), buffer.size()));
+
+ if (bytes_read == 0) {
+ break;
+ } else if (bytes_read < 0) {
+ ALOGD("read(%s): %s\n", logCombined.c_str(), strerror(errno));
+ break;
+ }
+
+ ssize_t result = TEMP_FAILURE_RETRY(write(fd_bin, buffer.data(), bytes_read));
+
+ if (result != bytes_read) {
+ ALOGD("Failed to write %zd bytes, actually written: %zd", bytes_read, result);
+ break;
+ }
+ }
+ }
+
+ RunCommandToFd(fd, "RM LOG DIR", { "/vendor/bin/rm", "-r", logAllDir.c_str()}, CommandOptions::WithTimeout(2).Build());
+ RunCommandToFd(fd, "RM LOG", { "/vendor/bin/rm", logCombined.c_str()}, CommandOptions::WithTimeout(2).Build());
+}
+
+ndk::ScopedAStatus Dumpstate::dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds,
+ IDumpstateDevice::DumpstateMode in_mode,
+ int64_t in_timeoutMillis) {
+ // Unused arguments.
+ (void) in_timeoutMillis;
+ (void) in_mode;
+
+ if (in_fds.size() < 1) {
+ ALOGE("no FDs\n");
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "No file descriptor");
+ }
+
+ int fd = in_fds[0].get();
+ if (fd < 0) {
+ ALOGE("invalid FD: %d\n", fd);
+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
+ "Invalid file descriptor");
+ }
+
+ if (in_fds.size() < 2) {
+ ALOGE("no FD for dumpstate_board binary\n");
+ } else {
+ int fd_bin = in_fds[1].get();
+ dumpLogSection(fd, fd_bin);
+ }
+
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Dumpstate::setVerboseLoggingEnabled(bool in_enable) {
+ ::android::base::SetProperty(kVerboseLoggingProperty, in_enable ? "true" : "false");
+ return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus Dumpstate::getVerboseLoggingEnabled(bool* _aidl_return) {
+ *_aidl_return = ::android::base::GetBoolProperty(kVerboseLoggingProperty, false);
+ return ndk::ScopedAStatus::ok();
+}
+
+// Since AIDLs that support the dump() interface are automatically invoked during
+// bugreport generation and we don't want to generate a second copy of the same
+// data that will go into dumpstate_board.txt, this function will only do
+// something if it is called with an option, e.g.
+// dumpsys android.hardware.dumpstate.IDumpstateDevice/default all
+//
+// Also, note that sections which generate attachments and/or binary data when
+// included in a bugreport are not available through the dump() interface.
+binder_status_t Dumpstate::dump(int fd, const char** args, uint32_t numArgs) {
+
+ if (numArgs != 1) {
+ return STATUS_OK;
+ }
+
+ dumpTextSection(fd, static_cast<std::string>(args[0]));
+
+ fsync(fd);
+ return STATUS_OK;
+}
+
+} // namespace dumpstate
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/gear/dumpstate/Dumpstate.h b/gear/dumpstate/Dumpstate.h
new file mode 100644
index 0000000..787b774
--- /dev/null
+++ b/gear/dumpstate/Dumpstate.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/dumpstate/BnDumpstateDevice.h>
+#include <aidl/android/hardware/dumpstate/IDumpstateDevice.h>
+#include <android/binder_status.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace dumpstate {
+
+class Dumpstate : public BnDumpstateDevice {
+ public:
+ ::ndk::ScopedAStatus dumpstateBoard(const std::vector<::ndk::ScopedFileDescriptor>& in_fds,
+ IDumpstateDevice::DumpstateMode in_mode,
+ int64_t in_timeoutMillis) override;
+
+ ::ndk::ScopedAStatus getVerboseLoggingEnabled(bool* _aidl_return) override;
+
+ ::ndk::ScopedAStatus setVerboseLoggingEnabled(bool in_enable) override;
+
+ binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
+
+ private:
+ const std::string kAllSections = "all";
+
+ void dumpTextSection(int fd, std::string const& sectionName);
+ void dumpLogSection(int fd, int fdModem);
+
+ //bool getVerboseLoggingEnabledImpl();
+ //::ndk::ScopedAStatus dumpstateBoardImpl(const int fd, const bool full);
+};
+
+} // namespace dumpstate
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/gear/dumpstate/aidl.mk b/gear/dumpstate/aidl.mk
new file mode 100644
index 0000000..0df64e9
--- /dev/null
+++ b/gear/dumpstate/aidl.mk
@@ -0,0 +1,3 @@
+PRODUCT_PACKAGES += android.hardware.dumpstate-service
+BOARD_VENDOR_SEPOLICY_DIRS += device/google/gs-common/gear/dumpstate/sepolicy
+
diff --git a/gear/dumpstate/android.hardware.dumpstate-service.rc b/gear/dumpstate/android.hardware.dumpstate-service.rc
new file mode 100644
index 0000000..ee69a68
--- /dev/null
+++ b/gear/dumpstate/android.hardware.dumpstate-service.rc
@@ -0,0 +1,5 @@
+service vendor.dumpstate-default /vendor/bin/hw/android.hardware.dumpstate-service
+ class hal
+ user system
+ group system shell
+ interface aidl android.hardware.dumpstate.IDumpstateDevice/default
diff --git a/gear/dumpstate/android.hardware.dumpstate-service.xml b/gear/dumpstate/android.hardware.dumpstate-service.xml
new file mode 100644
index 0000000..5e51b28
--- /dev/null
+++ b/gear/dumpstate/android.hardware.dumpstate-service.xml
@@ -0,0 +1,9 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.dumpstate</name>
+ <interface>
+ <name>IDumpstateDevice</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
+</manifest>
diff --git a/gear/dumpstate/sepolicy/file.te b/gear/dumpstate/sepolicy/file.te
new file mode 100644
index 0000000..6c686a0
--- /dev/null
+++ b/gear/dumpstate/sepolicy/file.te
@@ -0,0 +1,5 @@
+type radio_vendor_data_file, file_type, data_file_type;
+userdebug_or_eng(`
+ typeattribute radio_vendor_data_file mlstrustedobject;
+')
+
diff --git a/gear/dumpstate/sepolicy/file_contexts b/gear/dumpstate/sepolicy/file_contexts
new file mode 100644
index 0000000..5c65e43
--- /dev/null
+++ b/gear/dumpstate/sepolicy/file_contexts
@@ -0,0 +1,4 @@
+/vendor/bin/hw/android\.hardware\.dumpstate-service u:object_r:hal_dumpstate_default_exec:s0
+
+/data/vendor/radio(/.*)? u:object_r:radio_vendor_data_file:s0
+
diff --git a/gear/dumpstate/sepolicy/hal_dumpstate_default.te b/gear/dumpstate/sepolicy/hal_dumpstate_default.te
new file mode 100644
index 0000000..3e4db45
--- /dev/null
+++ b/gear/dumpstate/sepolicy/hal_dumpstate_default.te
@@ -0,0 +1,5 @@
+allow hal_dumpstate_default vendor_toolbox_exec:file execute_no_trans;
+allow hal_dumpstate_default radio_vendor_data_file:dir create_dir_perms;
+allow hal_dumpstate_default radio_vendor_data_file:file create_file_perms;
+allow hal_dumpstate_default shell_data_file:file getattr;
+
diff --git a/gear/dumpstate/service.cpp b/gear/dumpstate/service.cpp
new file mode 100644
index 0000000..848bddd
--- /dev/null
+++ b/gear/dumpstate/service.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#define LOG_TAG "android.hardware.dumpstate-service"
+
+#include "Dumpstate.h"
+
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::dumpstate::Dumpstate;
+
+int main() {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+ std::shared_ptr<Dumpstate> dumpstate = ndk::SharedRefBase::make<Dumpstate>();
+
+ const std::string instance = std::string() + Dumpstate::descriptor + "/default";
+ binder_status_t status =
+ AServiceManager_addService(dumpstate->asBinder().get(), instance.c_str());
+ CHECK_EQ(status, STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ return EXIT_FAILURE; // Unreachable
+}