1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <PowerStatsAidl.h> 20 21 #include <unordered_map> 22 23 namespace aidl { 24 namespace android { 25 namespace hardware { 26 namespace power { 27 namespace stats { 28 29 class IioEnergyMeterDataProvider : public PowerStats::IEnergyMeterDataProvider { 30 public: 31 IioEnergyMeterDataProvider(const std::vector<const std::string> &deviceNames, 32 const bool useSelector = false); 33 34 // Methods from PowerStats::IRailEnergyDataProvider 35 ndk::ScopedAStatus readEnergyMeter(const std::vector<int32_t> &in_channelIds, 36 std::vector<EnergyMeasurement> *_aidl_return) override; 37 ndk::ScopedAStatus getEnergyMeterInfo(std::vector<Channel> *_aidl_return) override; 38 39 private: 40 void findIioEnergyMeterNodes(); 41 void parseEnabledRails(); 42 int parseEnergyValue(std::string path); 43 int parseEnergyContents(const std::string &contents); 44 45 std::mutex mLock; 46 std::unordered_map<std::string, std::string> mDevicePaths; // key: path, value: device name 47 std::unordered_map<std::string, int32_t> mChannelIds; // key: name, value: id 48 std::vector<Channel> mChannelInfos; 49 std::vector<EnergyMeasurement> mReading; 50 51 const std::vector<const std::string> kDeviceNames; 52 const std::string kDeviceType = "iio:device"; 53 const std::string kIioRootDir = "/sys/bus/iio/devices/"; 54 const std::string kNameNode = "/name"; 55 const std::string kEnabledRailsNode = "/enabled_rails"; 56 const std::string kEnergyValueNode = "/energy_value"; 57 }; 58 59 } // namespace stats 60 } // namespace power 61 } // namespace hardware 62 } // namespace android 63 } // namespace aidl 64