• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "ability_manager_service.h"
19 #include "ability_util.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
AbilityEventHandler(const std::shared_ptr<TaskHandlerWrap> & taskHandler,const std::weak_ptr<AbilityManagerService> & server)23 AbilityEventHandler::AbilityEventHandler(
24     const std::shared_ptr<TaskHandlerWrap> &taskHandler, const std::weak_ptr<AbilityManagerService> &server)
25     : EventHandlerWrap(taskHandler), server_(server)
26 {
27     TAG_LOGI(AAFwkTag::ABILITYMGR, "constructors");
28 }
29 
ProcessEvent(const EventWrap & event)30 void AbilityEventHandler::ProcessEvent(const EventWrap &event)
31 {
32     TAG_LOGI(AAFwkTag::ABILITYMGR, "Event obtained: %{public}s.", event.GetEventString().c_str());
33     // check libc.hook_mode
34     const int bufferLen = 128;
35     char paramOutBuf[bufferLen] = {0};
36     const char *hook_mode = "startup:";
37     int ret = GetParameter("libc.hook_mode", "", paramOutBuf, bufferLen);
38     if (ret > 0 && strncmp(paramOutBuf, hook_mode, strlen(hook_mode)) == 0) {
39         TAG_LOGD(AAFwkTag::ABILITYMGR, "Hook_mode: no process time out");
40         return;
41     }
42     switch (event.GetEventId()) {
43         case AbilityManagerService::LOAD_HALF_TIMEOUT_MSG:
44             ProcessLoadTimeOut(event, true);
45             break;
46         case AbilityManagerService::LOAD_TIMEOUT_MSG:
47             ProcessLoadTimeOut(event, false);
48             break;
49         case AbilityManagerService::ACTIVE_TIMEOUT_MSG:
50             ProcessActiveTimeOut(event.GetParam());
51             break;
52         case AbilityManagerService::INACTIVE_TIMEOUT_MSG:
53             TAG_LOGD(AAFwkTag::ABILITYMGR, "Inactive timeout.");
54             // inactivate pre ability immediately in case blocking next ability start
55             ProcessInactiveTimeOut(event.GetParam());
56             break;
57         case AbilityManagerService::FOREGROUND_HALF_TIMEOUT_MSG:
58             ProcessForegroundTimeOut(event, true);
59             break;
60         case AbilityManagerService::FOREGROUND_TIMEOUT_MSG:
61             ProcessForegroundTimeOut(event, false);
62             break;
63         case AbilityManagerService::SHAREDATA_TIMEOUT_MSG:
64             ProcessShareDataTimeOut(event.GetParam());
65             break;
66         case AbilityManagerService::CONNECT_TIMEOUT_MSG:
67             ProcessConnectTimeOut(event, false);
68             break;
69         case AbilityManagerService::CONNECT_HALF_TIMEOUT_MSG:
70             ProcessConnectTimeOut(event, true);
71             break;
72         default:
73             TAG_LOGW(AAFwkTag::ABILITYMGR, "unsupported timeout message");
74             break;
75     }
76 }
77 
ProcessLoadTimeOut(const EventWrap & event,bool isHalf)78 void AbilityEventHandler::ProcessLoadTimeOut(const EventWrap &event, bool isHalf)
79 {
80     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
81     auto server = server_.lock();
82     CHECK_POINTER(server);
83     server->HandleLoadTimeOut(event.GetParam(), isHalf, event.IsExtension());
84 }
85 
ProcessActiveTimeOut(int64_t abilityRecordId)86 void AbilityEventHandler::ProcessActiveTimeOut(int64_t abilityRecordId)
87 {
88     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
89     auto server = server_.lock();
90     CHECK_POINTER(server);
91     server->HandleActiveTimeOut(abilityRecordId);
92 }
93 
ProcessInactiveTimeOut(int64_t abilityRecordId)94 void AbilityEventHandler::ProcessInactiveTimeOut(int64_t abilityRecordId)
95 {
96     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
97     auto server = server_.lock();
98     CHECK_POINTER(server);
99     server->HandleInactiveTimeOut(abilityRecordId);
100 }
101 
ProcessForegroundTimeOut(const EventWrap & event,bool isHalf)102 void AbilityEventHandler::ProcessForegroundTimeOut(const EventWrap &event, bool isHalf)
103 {
104     TAG_LOGI(AAFwkTag::ABILITYMGR, "foreground timeout");
105     auto server = server_.lock();
106     CHECK_POINTER(server);
107     server->HandleForegroundTimeOut(event.GetParam(), isHalf, event.IsExtension());
108 }
109 
ProcessShareDataTimeOut(int64_t uniqueId)110 void AbilityEventHandler::ProcessShareDataTimeOut(int64_t uniqueId)
111 {
112     TAG_LOGI(AAFwkTag::ABILITYMGR, "shareData timeout");
113     auto server = server_.lock();
114     CHECK_POINTER(server);
115     server->HandleShareDataTimeOut(uniqueId);
116 }
117 
ProcessConnectTimeOut(const EventWrap & event,bool isHalf)118 void AbilityEventHandler::ProcessConnectTimeOut(const EventWrap &event, bool isHalf)
119 {
120     TAG_LOGI(AAFwkTag::ABILITYMGR, "connect timeout");
121     auto server = server_.lock();
122     CHECK_POINTER(server);
123     server->HandleConnectTimeOut(event.GetParam(), isHalf);
124 }
125 
126 }  // namespace AAFwk
127 }  // namespace OHOS
128