1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef CLIENT_TYPE_MANAGER_HANDLER_H 16 #define CLIENT_TYPE_MANAGER_HANDLER_H 17 #include <mutex> 18 19 #include "singleton.h" 20 #include "event_handler.h" 21 #include "event_runner.h" 22 23 #include "audio_info.h" 24 #include "audio_policy_log.h" 25 #include "audio_system_manager.h" 26 #include "i_standard_audio_policy_manager_listener.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 using namespace std; 31 32 enum ClientType { 33 CLIENT_TYPE_OTHERS = 0, 34 CLIENT_TYPE_GAME = 1, 35 }; 36 37 class ClientTypeListener { 38 public: 39 virtual ~ClientTypeListener() = default; 40 41 virtual void OnClientTypeQueryCompleted(uint32_t uid, ClientType clientType) = 0; 42 }; 43 44 class ClientTypeManagerHandler : public AppExecFwk::EventHandler { 45 public: 46 ClientTypeManagerHandler(); 47 ~ClientTypeManagerHandler(); 48 49 void ReleaseEventRunner(); 50 51 enum EventClientTypeManagerCmd { 52 GET_CLIENT_TYPE, 53 }; 54 55 class EventObj { 56 public: 57 std::string bundleName; 58 uint32_t uid; 59 }; 60 61 void RegisterClientTypeListener(ClientTypeListener *clientTypeListener); 62 bool SendGetClientType(const std::string &bundleName, uint32_t uid); 63 64 void SetQueryClientTypeCallback(const sptr<IStandardAudioPolicyManagerListener> &callback); 65 66 protected: 67 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 68 69 private: 70 /* Handle Event*/ 71 void HandleGetClientType(const AppExecFwk::InnerEvent::Pointer &event); 72 ClientTypeListener *clientTypeListener_ = nullptr; 73 std::mutex runnerMutex_; 74 75 std::mutex callbackMutex_; 76 sptr<IStandardAudioPolicyManagerListener> queryClientTypeCallback_ = nullptr; 77 }; 78 } // namespace AudioStandard 79 } // namespace OHOS 80 #endif // CLIENT_TYPE_MANAGER_HANDLER_H 81