1 /* 2 * Copyright (C) 2022 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 "AocStateResidencyDataProvider.h" 19 20 #include <condition_variable> 21 #include <mutex> 22 #include <thread> 23 #include <PowerStatsAidl.h> 24 25 namespace aidl { 26 namespace android { 27 namespace hardware { 28 namespace power { 29 namespace stats { 30 31 enum AsyncStatus { 32 COMPLETED, 33 RUN, 34 RUNNING 35 }; 36 37 class AocTimedStateResidencyDataProvider : public AocStateResidencyDataProvider { 38 public: 39 AocTimedStateResidencyDataProvider( 40 std::vector<std::pair<std::string, std::string>> ids, 41 std::vector<std::pair<std::string, std::string>> states, 42 const uint64_t timeoutMillis, 43 const uint64_t aocClock); 44 ~AocTimedStateResidencyDataProvider() = default; 45 46 bool getStateResidencies( 47 std::unordered_map<std::string, std::vector<StateResidency>> *residencies) override; 48 49 private: 50 void getStateResidenciesAsync(); 51 52 uint64_t mTimeoutMillis; 53 std::thread mAsyncThread; 54 std::mutex mStatusMutex; 55 std::condition_variable mRunCond; 56 std::condition_variable mCompletedCond; 57 std::unordered_map<std::string, std::vector<StateResidency>> mStateResidencies; 58 AsyncStatus mAsyncStatus; 59 }; 60 61 } // namespace stats 62 } // namespace power 63 } // namespace hardware 64 } // namespace android 65 } // namespace aidl 66