1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved. 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 IN_CALL_OBSERVER_H 17 #define IN_CALL_OBSERVER_H 18 19 #include <mutex> 20 #include <vector> 21 #include <unordered_map> 22 #include <chrono> 23 #include <atomic> 24 #include "media_telephony_listener.h" 25 #include "screen_capture.h" 26 27 namespace OHOS { 28 namespace Media { 29 30 class InCallObserverCallBack { 31 public: 32 virtual ~InCallObserverCallBack() = default; 33 virtual bool StopAndRelease(AVScreenCaptureStateCode state); 34 }; 35 36 class InCallObserver { 37 public: 38 39 static InCallObserver& GetInstance(); 40 bool RegisterObserver(); 41 void UnRegisterObserver(); 42 bool OnCallStateUpdated(bool inCall); 43 bool IsInCall(); 44 bool RegisterInCallObserverCallBack(std::weak_ptr<InCallObserverCallBack> inCallObserverCallBack); 45 void UnRegisterInCallObserverCallBack(); 46 47 private: 48 49 std::vector<MediaTelephonyListener *> mediaTelephonyListeners_; 50 std::weak_ptr<InCallObserverCallBack> inCallObserverCallBack_; 51 InCallObserver(); 52 ~InCallObserver(); 53 std::atomic<bool> inCall_{false}; 54 std::mutex mutex_; 55 bool Init(); 56 bool isTelephonyStateListenerDied_ = true; 57 }; 58 } 59 } 60 #endif // IN_CALL_OBSERVER_H