1 /* 2 * Copyright (C) 2024 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 "PowerStatsProvider.h" 18 #include <aidl/android/hardware/health/IHealth.h> 19 #include <android-base/logging.h> 20 #include <android/binder_manager.h> 21 #include <mediautils/ServiceSingleton.h> 22 23 using ::aidl::android::hardware::health::HealthInfo; 24 using ::aidl::android::hardware::health::IHealth; 25 26 namespace android::media::psh_utils { 27 getHealthService()28static auto getHealthService() { 29 return mediautils::getService<IHealth>(); 30 } 31 fill(PowerStats * stat) const32status_t HealthStatsDataProvider::fill(PowerStats* stat) const { 33 if (stat == nullptr) return BAD_VALUE; 34 HealthStats& stats = stat->health_stats; 35 auto healthService = getHealthService(); 36 if (healthService == nullptr) { 37 return NO_INIT; 38 } 39 HealthInfo healthInfo; 40 if (!healthService->getHealthInfo(&healthInfo).isOk()) { 41 LOG(ERROR) << __func__ << ": unable to get health info"; 42 return INVALID_OPERATION; 43 } 44 45 stats.batteryVoltageMillivolts = healthInfo.batteryVoltageMillivolts; 46 stats.batteryFullChargeUah = healthInfo.batteryFullChargeUah; 47 stats.batteryChargeCounterUah = healthInfo.batteryChargeCounterUah; 48 return NO_ERROR; 49 } 50 51 } // namespace android::media::psh_utils 52