1 /* 2 * Copyright (c) 2025 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 SCREENLOCK_STATUS_LISTENER_H 17 #define SCREENLOCK_STATUS_LISTENER_H 18 19 #include "common_event_manager.h" 20 #include "common_event_subscriber.h" 21 #include "common_event_support.h" 22 #include "system_ability_definition.h" 23 24 #include "iam_check.h" 25 #include "iam_common_defines.h" 26 #include "iam_logger.h" 27 #include "iam_ptr.h" 28 #include "system_ability_listener.h" 29 30 namespace OHOS { 31 namespace UserIam { 32 namespace UserAuth { 33 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 34 using CommonEventData = OHOS::EventFwk::CommonEventData; 35 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 36 37 class ScreenlockStatusListener : public CommonEventSubscriber { 38 public: ScreenlockStatusListener(const CommonEventSubscribeInfo & subscriberInfo)39 explicit ScreenlockStatusListener(const CommonEventSubscribeInfo &subscriberInfo) 40 : CommonEventSubscriber(subscriberInfo) {} 41 ~ScreenlockStatusListener() = default; 42 43 void OnReceiveEvent(const CommonEventData &data) override; 44 }; 45 46 class ScreenlockStatusListenerManager { 47 public: 48 static ScreenlockStatusListenerManager &GetInstance(); 49 50 ResultCode RegisterCommonEventListener(); 51 52 private: 53 ScreenlockStatusListenerManager() = default; 54 ~ScreenlockStatusListenerManager() = default; 55 56 void RegisterScreenLockedCallback(); 57 void UnRegisterScreenLockedCallback(); 58 void SyncScreenlockStatus(); 59 60 std::shared_ptr<ScreenlockStatusListener> subscriber_ {nullptr}; 61 sptr<SystemAbilityListener> commonEventSaStatusListener_ {nullptr}; 62 std::recursive_mutex mutex_; 63 }; 64 } // namespace UserAuth 65 } // namespace UserIam 66 } // namespace OHOS 67 #endif // SCREENLOCK_STATUS_LISTENER_H