1 /* 2 * Copyright (c) 2021 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 "ability_event_handler.h" 17 18 #include "hilog_wrapper.h" 19 #include "ability_util.h" 20 #include "ability_manager_service.h" 21 22 namespace OHOS { 23 namespace AAFwk { AbilityEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner,const std::weak_ptr<AbilityManagerService> & server)24AbilityEventHandler::AbilityEventHandler( 25 const std::shared_ptr<AppExecFwk::EventRunner> &runner, const std::weak_ptr<AbilityManagerService> &server) 26 : AppExecFwk::EventHandler(runner), server_(server) 27 { 28 HILOG_INFO("Constructors."); 29 } 30 ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)31void AbilityEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) 32 { 33 CHECK_POINTER(event); 34 HILOG_DEBUG("Event id obtained: %{public}u.", event->GetInnerEventId()); 35 switch (event->GetInnerEventId()) { 36 case AbilityManagerService::LOAD_TIMEOUT_MSG: { 37 ProcessLoadTimeOut(event->GetParam()); 38 break; 39 } 40 case AbilityManagerService::ACTIVE_TIMEOUT_MSG: { 41 ProcessActiveTimeOut(event->GetParam()); 42 break; 43 } 44 case AbilityManagerService::INACTIVE_TIMEOUT_MSG: { 45 HILOG_INFO("Inactive timeout."); 46 // inactivate pre ability immediately in case blocking next ability start 47 ProcessInactiveTimeOut(event->GetParam()); 48 break; 49 } 50 default: { 51 HILOG_WARN("Unsupported timeout message."); 52 break; 53 } 54 } 55 } 56 ProcessLoadTimeOut(int64_t eventId)57void AbilityEventHandler::ProcessLoadTimeOut(int64_t eventId) 58 { 59 HILOG_INFO("Attach timeout."); 60 auto server = server_.lock(); 61 CHECK_POINTER(server); 62 server->HandleLoadTimeOut(eventId); 63 } 64 ProcessActiveTimeOut(int64_t eventId)65void AbilityEventHandler::ProcessActiveTimeOut(int64_t eventId) 66 { 67 HILOG_INFO("Active timeout."); 68 auto server = server_.lock(); 69 CHECK_POINTER(server); 70 server->HandleActiveTimeOut(eventId); 71 } ProcessInactiveTimeOut(int64_t eventId)72void AbilityEventHandler::ProcessInactiveTimeOut(int64_t eventId) 73 { 74 HILOG_INFO("Inactive timeout."); 75 auto server = server_.lock(); 76 CHECK_POINTER(server); 77 server->HandleInactiveTimeOut(eventId); 78 } 79 } // namespace AAFwk 80 } // namespace OHOS