/* * Copyright (C) 2020 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 #include #include namespace aidl { namespace android { namespace hardware { namespace power { namespace stats { class PowerStats : public BnPowerStats { public: class IStateResidencyDataProvider { public: virtual ~IStateResidencyDataProvider() = default; virtual bool getStateResidencies( std::unordered_map> *residencies) = 0; virtual std::unordered_map> getInfo() = 0; virtual void registerStatesUpdateCallback( __unused std::function &)>) {} }; class IEnergyConsumer { public: virtual ~IEnergyConsumer() = default; virtual std::pair getInfo() = 0; virtual std::optional getEnergyConsumed() = 0; virtual std::string getConsumerName() = 0; }; class IEnergyMeterDataProvider { public: virtual ~IEnergyMeterDataProvider() = default; virtual ndk::ScopedAStatus readEnergyMeter( const std::vector &in_channelIds, std::vector *_aidl_return) = 0; virtual ndk::ScopedAStatus getEnergyMeterInfo(std::vector *_aidl_return) = 0; }; PowerStats() = default; void addStateResidencyDataProvider(std::unique_ptr p); void addEnergyConsumer(std::unique_ptr p); void setEnergyMeterDataProvider(std::unique_ptr p); // Methods from aidl::android::hardware::power::stats::IPowerStats ndk::ScopedAStatus getPowerEntityInfo(std::vector *_aidl_return) override; ndk::ScopedAStatus getStateResidency(const std::vector &in_powerEntityIds, std::vector *_aidl_return) override; ndk::ScopedAStatus getEnergyConsumerInfo(std::vector *_aidl_return) override; ndk::ScopedAStatus getEnergyConsumed(const std::vector &in_energyConsumerIds, std::vector *_aidl_return) override; ndk::ScopedAStatus getEnergyMeterInfo(std::vector *_aidl_return) override; ndk::ScopedAStatus readEnergyMeter(const std::vector &in_channelIds, std::vector *_aidl_return) override; binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; private: void statesUpdate(const std::string &entityName, const std::vector &states); void getEntityStateNames( std::unordered_map *entityNames, std::unordered_map> *stateNames); void getChannelNames(std::unordered_map *channelNames); void dumpStateResidency(std::ostringstream &oss, bool delta); void dumpStateResidencyDelta(std::ostringstream &oss, const std::vector &results); void dumpStateResidencyOneShot(std::ostringstream &oss, const std::vector &results); void dumpEnergyConsumer(std::ostringstream &oss, bool delta); void dumpEnergyMeter(std::ostringstream &oss, bool delta); std::vector> mStateResidencyDataProviders; std::vector mPowerEntityInfos; /* Index that maps each power entity id to an entry in mStateResidencyDataProviders */ std::vector mStateResidencyDataProviderIndex; std::vector> mEnergyConsumers; std::vector mEnergyConsumerInfos; std::unique_ptr mEnergyMeterDataProvider; }; } // namespace stats } // namespace power } // namespace hardware } // namespace android } // namespace aidl