summaryrefslogtreecommitdiff
path: root/health
diff options
context:
space:
mode:
authorGeorge Lee <geolee@google.com>2019-05-10 16:08:29 -0700
committerGeorge Lee <geolee@google.com>2019-05-20 19:09:02 -0700
commita6949e1ac32c5f54b0cb47dcef9ff5fdb856e8f1 (patch)
tree274bf4ada6e6680139f5d78de1e6ff629c16f4fe /health
parentbdc01697f47f61d7bc1dc3feeede2fc4dc9a156d (diff)
downloadpixel-a6949e1ac32c5f54b0cb47dcef9ff5fdb856e8f1.tar.gz
Thermal: Disable SoC throttling when Charging
SOC Based throttling is disabled when charging is enabled. Throttling is re-enabled once charging is removed. Bug: 131314951 Test: Use emul_temp and battery/capacity to emulate condition for checking if SOC thermal zone is disabled/enabled. Change-Id: Ib3dc52eaf1d6ec0ff4d8e87e134d839385e69948 Signed-off-by: George Lee <geolee@google.com>
Diffstat (limited to 'health')
-rw-r--r--health/Android.bp5
-rw-r--r--health/BatteryThermalControl.cpp52
-rw-r--r--health/include/pixelhealth/BatteryThermalControl.h52
3 files changed, 107 insertions, 2 deletions
diff --git a/health/Android.bp b/health/Android.bp
index 99d65826..256bf126 100644
--- a/health/Android.bp
+++ b/health/Android.bp
@@ -4,10 +4,11 @@ cc_library {
export_include_dirs: ["include"],
srcs: [
- "LowBatteryShutdownMetrics.cpp",
+ "BatteryMetricsLogger.cpp",
+ "BatteryThermalControl.cpp",
"CycleCountBackupRestore.cpp",
"DeviceHealth.cpp",
- "BatteryMetricsLogger.cpp",
+ "LowBatteryShutdownMetrics.cpp",
],
cflags: [
diff --git a/health/BatteryThermalControl.cpp b/health/BatteryThermalControl.cpp
new file mode 100644
index 00000000..d119b34c
--- /dev/null
+++ b/health/BatteryThermalControl.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+#include "pixelhealth/BatteryThermalControl.h"
+
+namespace hardware {
+namespace google {
+namespace pixel {
+namespace health {
+
+BatteryThermalControl::BatteryThermalControl(const std::string &path) : mThermalSocMode(path) {
+ mStatus = true;
+}
+
+void BatteryThermalControl::setThermalMode(bool isEnable, bool isWeakCharger) {
+ std::string action = (isEnable) ? "enabled" : "disabled";
+
+ if (mStatus != isEnable) {
+ if (!isEnable && isWeakCharger)
+ return;
+ if (android::base::WriteStringToFile(action, mThermalSocMode)) {
+ mStatus = isEnable;
+ } else {
+ LOG(ERROR) << "Error Write: \"" << action << "\" to " << mThermalSocMode
+ << " error:" << strerror(errno);
+ }
+ }
+}
+
+void BatteryThermalControl::updateThermalState(const struct android::BatteryProperties *props) {
+ setThermalMode(props->batteryStatus != android::BATTERY_STATUS_CHARGING &&
+ props->batteryStatus != android::BATTERY_STATUS_FULL,
+ props->maxChargingCurrent * props->maxChargingVoltage < 37500000);
+}
+
+} // namespace health
+} // namespace pixel
+} // namespace google
+} // namespace hardware
diff --git a/health/include/pixelhealth/BatteryThermalControl.h b/health/include/pixelhealth/BatteryThermalControl.h
new file mode 100644
index 00000000..4b15220d
--- /dev/null
+++ b/health/include/pixelhealth/BatteryThermalControl.h
@@ -0,0 +1,52 @@
+/*
+ * 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 <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/strings.h>
+#include <batteryservice/BatteryService.h>
+
+#include <string>
+
+namespace hardware {
+namespace google {
+namespace pixel {
+namespace health {
+
+/**
+ * updateThermalState is called per battery status update.
+ * BatteryThermalControl monitors thermal framework and when device is charging
+ * or battery is full, it then disable SOC throtting by setting disabled in
+ * SOC thermal zone's mode.
+ */
+class BatteryThermalControl {
+ public:
+ BatteryThermalControl(const std::string &path);
+ void updateThermalState(const struct android::BatteryProperties *props);
+
+ private:
+ void setThermalMode(bool isEnable, bool isWeakCharger);
+
+ const std::string mThermalSocMode;
+ bool mStatus;
+};
+
+} // namespace health
+} // namespace pixel
+} // namespace google
+} // namespace hardware