1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include "ability_event_handler.h" 17eace7efcSopenharmony_ci 18eace7efcSopenharmony_ci#include "ability_manager_service.h" 19eace7efcSopenharmony_ci#include "ability_util.h" 20eace7efcSopenharmony_ci 21eace7efcSopenharmony_cinamespace OHOS { 22eace7efcSopenharmony_cinamespace AAFwk { 23eace7efcSopenharmony_ciAbilityEventHandler::AbilityEventHandler( 24eace7efcSopenharmony_ci const std::shared_ptr<TaskHandlerWrap> &taskHandler, const std::weak_ptr<AbilityManagerService> &server) 25eace7efcSopenharmony_ci : EventHandlerWrap(taskHandler), server_(server) 26eace7efcSopenharmony_ci{ 27eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "constructors"); 28eace7efcSopenharmony_ci} 29eace7efcSopenharmony_ci 30eace7efcSopenharmony_civoid AbilityEventHandler::ProcessEvent(const EventWrap &event) 31eace7efcSopenharmony_ci{ 32eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Event id obtained: %{public}u.", event.GetEventId()); 33eace7efcSopenharmony_ci // check libc.hook_mode 34eace7efcSopenharmony_ci const int bufferLen = 128; 35eace7efcSopenharmony_ci char paramOutBuf[bufferLen] = {0}; 36eace7efcSopenharmony_ci const char *hook_mode = "startup:"; 37eace7efcSopenharmony_ci int ret = GetParameter("libc.hook_mode", "", paramOutBuf, bufferLen); 38eace7efcSopenharmony_ci if (ret > 0 && strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) == 0) { 39eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Hook_mode: no process time out"); 40eace7efcSopenharmony_ci return; 41eace7efcSopenharmony_ci } 42eace7efcSopenharmony_ci switch (event.GetEventId()) { 43eace7efcSopenharmony_ci case AbilityManagerService::LOAD_HALF_TIMEOUT_MSG: { 44eace7efcSopenharmony_ci ProcessLoadTimeOut(event, true); 45eace7efcSopenharmony_ci break; 46eace7efcSopenharmony_ci } 47eace7efcSopenharmony_ci case AbilityManagerService::LOAD_TIMEOUT_MSG: { 48eace7efcSopenharmony_ci ProcessLoadTimeOut(event, false); 49eace7efcSopenharmony_ci break; 50eace7efcSopenharmony_ci } 51eace7efcSopenharmony_ci case AbilityManagerService::ACTIVE_TIMEOUT_MSG: { 52eace7efcSopenharmony_ci ProcessActiveTimeOut(event.GetParam()); 53eace7efcSopenharmony_ci break; 54eace7efcSopenharmony_ci } 55eace7efcSopenharmony_ci case AbilityManagerService::INACTIVE_TIMEOUT_MSG: { 56eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "Inactive timeout."); 57eace7efcSopenharmony_ci // inactivate pre ability immediately in case blocking next ability start 58eace7efcSopenharmony_ci ProcessInactiveTimeOut(event.GetParam()); 59eace7efcSopenharmony_ci break; 60eace7efcSopenharmony_ci } 61eace7efcSopenharmony_ci case AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG: { 62eace7efcSopenharmony_ci ProcessForegroundTimeOut(event, true); 63eace7efcSopenharmony_ci break; 64eace7efcSopenharmony_ci } 65eace7efcSopenharmony_ci case AbilityManagerService::FOREGROUND_TIMEOUT_MSG: { 66eace7efcSopenharmony_ci ProcessForegroundTimeOut(event, false); 67eace7efcSopenharmony_ci break; 68eace7efcSopenharmony_ci } 69eace7efcSopenharmony_ci case AbilityManagerService::SHAREDATA_TIMEOUT_MSG: { 70eace7efcSopenharmony_ci ProcessShareDataTimeOut(event.GetParam()); 71eace7efcSopenharmony_ci break; 72eace7efcSopenharmony_ci } 73eace7efcSopenharmony_ci default: { 74eace7efcSopenharmony_ci TAG_LOGW(AAFwkTag::ABILITYMGR, "unsupported timeout message"); 75eace7efcSopenharmony_ci break; 76eace7efcSopenharmony_ci } 77eace7efcSopenharmony_ci } 78eace7efcSopenharmony_ci} 79eace7efcSopenharmony_ci 80eace7efcSopenharmony_civoid AbilityEventHandler::ProcessLoadTimeOut(const EventWrap &event, bool isHalf) 81eace7efcSopenharmony_ci{ 82eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); 83eace7efcSopenharmony_ci auto server = server_.lock(); 84eace7efcSopenharmony_ci CHECK_POINTER(server); 85eace7efcSopenharmony_ci server->HandleLoadTimeOut(event.GetParam(), isHalf, event.IsExtension()); 86eace7efcSopenharmony_ci} 87eace7efcSopenharmony_ci 88eace7efcSopenharmony_civoid AbilityEventHandler::ProcessActiveTimeOut(int64_t abilityRecordId) 89eace7efcSopenharmony_ci{ 90eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); 91eace7efcSopenharmony_ci auto server = server_.lock(); 92eace7efcSopenharmony_ci CHECK_POINTER(server); 93eace7efcSopenharmony_ci server->HandleActiveTimeOut(abilityRecordId); 94eace7efcSopenharmony_ci} 95eace7efcSopenharmony_ci 96eace7efcSopenharmony_civoid AbilityEventHandler::ProcessInactiveTimeOut(int64_t abilityRecordId) 97eace7efcSopenharmony_ci{ 98eace7efcSopenharmony_ci TAG_LOGD(AAFwkTag::ABILITYMGR, "called"); 99eace7efcSopenharmony_ci auto server = server_.lock(); 100eace7efcSopenharmony_ci CHECK_POINTER(server); 101eace7efcSopenharmony_ci server->HandleInactiveTimeOut(abilityRecordId); 102eace7efcSopenharmony_ci} 103eace7efcSopenharmony_ci 104eace7efcSopenharmony_civoid AbilityEventHandler::ProcessForegroundTimeOut(const EventWrap &event, bool isHalf) 105eace7efcSopenharmony_ci{ 106eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "foreground timeout"); 107eace7efcSopenharmony_ci auto server = server_.lock(); 108eace7efcSopenharmony_ci CHECK_POINTER(server); 109eace7efcSopenharmony_ci server->HandleForegroundTimeOut(event.GetParam(), isHalf, event.IsExtension()); 110eace7efcSopenharmony_ci} 111eace7efcSopenharmony_ci 112eace7efcSopenharmony_civoid AbilityEventHandler::ProcessShareDataTimeOut(int64_t uniqueId) 113eace7efcSopenharmony_ci{ 114eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::ABILITYMGR, "shareData timeout"); 115eace7efcSopenharmony_ci auto server = server_.lock(); 116eace7efcSopenharmony_ci CHECK_POINTER(server); 117eace7efcSopenharmony_ci server->HandleShareDataTimeOut(uniqueId); 118eace7efcSopenharmony_ci} 119eace7efcSopenharmony_ci 120eace7efcSopenharmony_ci} // namespace AAFwk 121eace7efcSopenharmony_ci} // namespace OHOS 122