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