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 BatteryThermalControl(const std::string & path)24BatteryThermalControl::BatteryThermalControl(const std::string &path) : mThermalSocMode(path) { 25 mStatus = true; 26 } 27 setThermalMode(bool isEnable,bool isWeakCharger)28void BatteryThermalControl::setThermalMode(bool isEnable, bool isWeakCharger) { 29 std::string action = (isEnable) ? "enabled" : "disabled"; 30 31 if (mStatus != isEnable) { 32 if (!isEnable && isWeakCharger) 33 return; 34 if (android::base::WriteStringToFile(action, mThermalSocMode)) { 35 mStatus = isEnable; 36 } else { 37 LOG(ERROR) << "Error Write: \"" << action << "\" to " << mThermalSocMode 38 << " error:" << strerror(errno); 39 } 40 } 41 } 42 updateThermalState(const struct android::BatteryProperties * props)43void BatteryThermalControl::updateThermalState(const struct android::BatteryProperties *props) { 44 setThermalMode(props->batteryStatus != android::BATTERY_STATUS_CHARGING && 45 props->batteryStatus != android::BATTERY_STATUS_FULL, 46 props->maxChargingCurrent * props->maxChargingVoltage < 37500000); 47 } 48 49 } // namespace health 50 } // namespace pixel 51 } // namespace google 52 } // namespace hardware 53