1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "pixelhealth/BatteryThermalControl.h"
18
19 namespace hardware {
20 namespace google {
21 namespace pixel {
22 namespace health {
23
24 using android::base::GetIntProperty;
25
BatteryThermalControl(const std::string & path)26 BatteryThermalControl::BatteryThermalControl(const std::string &path) : mThermalSocMode(path) {
27 mStatus = true;
28 }
29
setThermalMode(bool isEnable,bool isWeakCharger)30 void BatteryThermalControl::setThermalMode(bool isEnable, bool isWeakCharger) {
31 std::string action = (isEnable) ? "enabled" : "disabled";
32
33 if (mStatus != isEnable) {
34 if (!isEnable && isWeakCharger)
35 return;
36 if (android::base::WriteStringToFile(action, mThermalSocMode)) {
37 mStatus = isEnable;
38 } else {
39 LOG(ERROR) << "Error Write: \"" << action << "\" to " << mThermalSocMode
40 << " error:" << strerror(errno);
41 }
42 }
43 }
44
updateThermalState(const struct android::BatteryProperties * props)45 void BatteryThermalControl::updateThermalState(const struct android::BatteryProperties *props) {
46 int bcl_disable = GetIntProperty("persist.vendor.disable.bcl.control", 0);
47
48 if (bcl_disable)
49 setThermalMode(false, true);
50 else
51 setThermalMode(props->batteryStatus != android::BATTERY_STATUS_CHARGING &&
52 props->batteryStatus != android::BATTERY_STATUS_FULL,
53 props->maxChargingCurrent * props->maxChargingVoltage < 37500000);
54 }
55
56 } // namespace health
57 } // namespace pixel
58 } // namespace google
59 } // namespace hardware
60