1 /*
2  * Copyright (C) 2023 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 #pragma once
17 
18 #include <PowerStatsAidl.h>
19 
20 namespace aidl {
21 namespace android {
22 namespace hardware {
23 namespace power {
24 namespace stats {
25 
26 class DisplayMrrStateResidencyDataProvider : public PowerStats::IStateResidencyDataProvider {
27   public:
28     DisplayMrrStateResidencyDataProvider(const std::string& name, const std::string& path);
29     ~DisplayMrrStateResidencyDataProvider() = default;
30 
31     /*
32      * See IStateResidencyDataProvider::getStateResidencies
33      */
34     bool getStateResidencies(
35         std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override;
36 
37     /*
38      * See IStateResidencyDataProvider::getInfo
39      */
40     std::unordered_map<std::string, std::vector<State>> getInfo() override;
41 
42   private:
43     struct Config {
44       int32_t state; // Display state (On, HBM, LP, Off)
45       int32_t resX;  // Resolution X
46       int32_t resY;  // Resolution Y
47       int32_t rr;    // Refresh rate
48 
49       bool operator==(const Config& r) const {
50         return state == r.state && resX == r.resX && resY == r.resY && rr == r.rr;
51       }
52     };
53 
54     bool parseConfig(char const *line, Config *config, uint64_t *duration);
55     bool parseAvailableState(char const *line, Config *config);
56     bool parseTimeInState(char const *line, Config *config, uint64_t *duration);
57     bool loadAvailableState();
58 
59     const std::string mName;
60     const std::string mPath;
61     std::vector<Config> mConfigs;
62 };
63 
64 }  // namespace stats
65 }  // namespace power
66 }  // namespace hardware
67 }  // namespace android
68 }  // namespace aidl
69