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 16 #ifndef IAM_ENROLL_CONTEXT_H 17 #define IAM_ENROLL_CONTEXT_H 18 19 #include "common_event_manager.h" 20 #include "common_event_subscriber.h" 21 #include "common_event_support.h" 22 #include "iam_common_defines.h" 23 #include "system_ability_definition.h" 24 #include "system_ability_listener.h" 25 26 namespace OHOS { 27 namespace UserIam { 28 namespace UserAuth { 29 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 30 using CommonEventData = OHOS::EventFwk::CommonEventData; 31 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 32 33 class KeyguardStatusListenerManager { 34 public: 35 KeyguardStatusListenerManager() = default; 36 ~KeyguardStatusListenerManager() = default; 37 38 static KeyguardStatusListenerManager &GetInstance(); 39 ResultCode RegisterCommonEventListener(); 40 ResultCode UnRegisterCommonEventListener(); 41 42 private: 43 void RegisterKeyguardStatusSwitchCallback(); 44 void UnRegisterKeyguardStatusSwitchCallback(); 45 46 bool isRegisterKeyguardStatus_ = false; 47 sptr<SystemAbilityListener> commonEventListener_ {nullptr}; 48 std::recursive_mutex mutex_; 49 }; 50 51 class KeyguardStatusListener : public CommonEventSubscriber { 52 public: KeyguardStatusListener(const CommonEventSubscribeInfo & subscriberInfo)53 explicit KeyguardStatusListener(const CommonEventSubscribeInfo &subscriberInfo) 54 : CommonEventSubscriber(subscriberInfo) {} 55 ~KeyguardStatusListener() = default; 56 57 void OnReceiveEvent(const CommonEventData &data) override; 58 }; 59 } // namespace UserAuth 60 } // namespace UserIam 61 } // namespace OHOS 62 #endif // IAM_ENROLL_CONTEXT_H 63