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 #include "el5_filkey_manager_subscriber.h" 17 18 #include "common_event_support.h" 19 #include "el5_filekey_manager_log.h" 20 #include "el5_filekey_manager_service.h" 21 #include "want.h" 22 23 namespace OHOS { 24 namespace Security { 25 namespace AccessToken { 26 namespace { 27 constexpr uint32_t SCREEN_ON_DELAY_TIME = 30 * 1000; // 30s 28 } 29 El5FilekeyManagerSubscriber(const EventFwk::CommonEventSubscribeInfo & subscribeInfo)30El5FilekeyManagerSubscriber::El5FilekeyManagerSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo) 31 : EventFwk::CommonEventSubscriber(subscribeInfo) 32 { 33 } 34 OnReceiveEvent(const EventFwk::CommonEventData & data)35void El5FilekeyManagerSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) 36 { 37 auto want = data.GetWant(); 38 std::string action = want.GetAction(); 39 LOG_INFO("Receive event %{public}s.", action.c_str()); 40 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { 41 DelayedSingleton<El5FilekeyManagerService>::GetInstance()->PostDelayedUnloadTask(SCREEN_ON_DELAY_TIME); 42 } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { 43 // cancel unload task when screen is locked 44 DelayedSingleton<El5FilekeyManagerService>::GetInstance()->CancelDelayedUnloadTask(); 45 } 46 } 47 } // namespace AccessToken 48 } // namespace Security 49 } // namespace OHOS 50