1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 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 ACCOUNT_OBSERVER_H 17 #define ACCOUNT_OBSERVER_H 18 19 #include "os_account_subscribe_info.h" 20 #include "os_account_subscriber.h" 21 #include "account_listener.h" 22 #include "screen_capture.h" 23 24 namespace OHOS { 25 namespace Media { 26 class AccountObserverCallBack { 27 public: 28 virtual ~AccountObserverCallBack() = default; 29 virtual bool StopAndRelease(AVScreenCaptureStateCode state); 30 }; 31 32 class AccountObserver { 33 public: 34 static AccountObserver& GetInstance(); 35 bool RegisterObserver(); 36 void UnregisterObserver(); 37 explicit AccountObserver(); 38 ~AccountObserver(); 39 bool OnAccountsSwitch(); 40 bool RegisterAccountObserverCallBack(std::weak_ptr<AccountObserverCallBack> callback); 41 void UnregisterAccountObserverCallBack(); 42 private: 43 bool Init(); 44 45 std::weak_ptr<AccountObserverCallBack> accountObserverCallBack_; 46 std::atomic<bool> isAccountListenerDied_ = true; 47 std::shared_ptr<AccountListener> accountListener_ = nullptr; 48 std::mutex mutex_; 49 }; 50 } // namespace Media 51 } // namespace OHOS 52 #endif // ACCOUNT_OBSERVER_H