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 #pragma once 18 19 #include <psh_utils/PowerClientStats.h> 20 #include <psh_utils/Token.h> 21 22 #include <atomic> 23 #include <memory> 24 #include <string> 25 26 namespace android::media::psh_utils { 27 28 class AudioClientToken : public Token { 29 public: 30 AudioClientToken(std::shared_ptr<PowerClientStats> powerClientStats, pid_t pid, uid_t uid, 31 const std::string& additional); 32 ~AudioClientToken() override; 33 34 // AudioPowerManager may call toString() while AudioToken is in its dtor. 35 // It is safe so long as toString is final. 36 std::string toString() const final; 37 38 private: 39 const std::shared_ptr<PowerClientStats> mPowerClientStats; 40 const pid_t mPid; 41 const std::string mAdditional; 42 const size_t mId; 43 static constinit std::atomic<size_t> sIdCounter; 44 }; 45 46 class AudioThreadToken : public Token { 47 public: 48 AudioThreadToken( 49 pid_t tid, const std::string& wakeLockName, 50 WakeFlag wakeFlag, const std::string& additional); 51 ~AudioThreadToken() override; 52 53 // AudioPowerManager may call toString() while AudioToken is in its dtor. 54 // It is safe so long as toString is final. 55 std::string toString() const final; 56 57 private: 58 const pid_t mTid; 59 const std::string mWakeLockName; 60 const WakeFlag mWakeFlag; 61 const std::string mAdditional; 62 const size_t mId; 63 static constinit std::atomic<size_t> sIdCounter; 64 }; 65 66 class AudioTrackToken : public Token { 67 public: 68 AudioTrackToken( 69 std::shared_ptr<PowerClientStats> powerClientStats, const std::string& additional); 70 ~AudioTrackToken() override; 71 72 // AudioPowerManager may call toString() while AudioToken is in its dtor. 73 // It is safe so long as toString is final. 74 std::string toString() const final; 75 76 private: 77 const std::shared_ptr<PowerClientStats> mPowerClientStats; 78 const std::string mAdditional; 79 const size_t mId; 80 static constinit std::atomic<size_t> sIdCounter; 81 }; 82 83 } // namespace android::media::psh_utils 84