1 /* 2 * Copyright (C) 2021-2022 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 16 #ifndef TELEPHONY_WIRED_HEADSET_H 17 #define TELEPHONY_WIRED_HEADSET_H 18 #include <memory> 19 #include <mutex> 20 21 #include "event_handler.h" 22 #include "event_runner.h" 23 #include "singleton.h" 24 #include "call_state_listener_base.h" 25 26 namespace OHOS { 27 namespace Telephony { 28 class WiredHeadsetHandler : public AppExecFwk::EventHandler { 29 public: 30 WiredHeadsetHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner); 31 virtual ~WiredHeadsetHandler(); 32 void Init(); 33 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 34 }; 35 36 class WiredHeadset : public CallStateListenerBase { 37 DECLARE_DELAYED_SINGLETON(WiredHeadset) 38 public: 39 void Init(); 40 void NewCallCreated(sptr<CallBase> &callObjectPtr) override; 41 void CallDestroyed(const DisconnectedDetails &details) override; 42 void CallStateUpdated(sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState) override; 43 void IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content) override; 44 void IncomingCallActivated(sptr<CallBase> &callObjectPtr) override; 45 enum { 46 MEDIA_INITIALIZE_MSG = 0, 47 MEDIA_SET_ACTIVE_MSG, 48 MEDIA_SET_LEAVE_MSG, 49 }; 50 enum Buttontype { 51 SHORT_PRESS = 0, 52 LONG_PRESS, 53 }; 54 55 private: 56 std::shared_ptr<AppExecFwk::EventRunner> eventLoop_; 57 std::shared_ptr<WiredHeadsetHandler> handler_; 58 std::mutex mutex_; 59 }; 60 } // namespace Telephony 61 } // namespace OHOS 62 #endif // TELEPHONY_WIRED_HEADSET_H