1 /*
2 * Copyright (c) 2021-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 "app_death_recipient.h"
17 #include "app_mgr_service_inner.h"
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
22 namespace {
23 const std::string TASK_ON_REMOTE_DIED = "OnRemoteDiedTask";
24 } // namespace
25
OnRemoteDied(const wptr<IRemoteObject> & remote)26 void AppDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
27 {
28 if (remote == nullptr) {
29 TAG_LOGE(AAFwkTag::APPMGR, "remote is null");
30 return;
31 }
32
33 auto handler = handler_.lock();
34 if (!handler) {
35 TAG_LOGE(AAFwkTag::APPMGR, "handler is null");
36 return;
37 }
38 auto serviceInner = appMgrServiceInner_.lock();
39 if (!serviceInner) {
40 TAG_LOGE(AAFwkTag::APPMGR, "serviceInner is null");
41 return;
42 }
43
44 auto onRemoteDiedFunc = [serviceInner, remote,
45 isRenderProcess = isRenderProcess_,
46 isChildProcess = isChildProcess_]() {
47 serviceInner->OnRemoteDied(remote, isRenderProcess, isChildProcess);
48 };
49 handler->SubmitTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED);
50 }
51
SetTaskHandler(const std::shared_ptr<AAFwk::TaskHandlerWrap> & handler)52 void AppDeathRecipient::SetTaskHandler(const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler)
53 {
54 handler_ = handler;
55 }
56
SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> & serviceInner)57 void AppDeathRecipient::SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> &serviceInner)
58 {
59 appMgrServiceInner_ = serviceInner;
60 }
61
SetIsRenderProcess(bool isRenderProcess)62 void AppDeathRecipient::SetIsRenderProcess(bool isRenderProcess)
63 {
64 isRenderProcess_ = isRenderProcess;
65 }
66
SetIsChildProcess(bool isChildProcess)67 void AppDeathRecipient::SetIsChildProcess(bool isChildProcess)
68 {
69 isChildProcess_ = isChildProcess;
70 }
71
AppStateCallbackDeathRecipient(std::weak_ptr<AppMgrServiceInner> appMgrServiceInner)72 AppStateCallbackDeathRecipient::AppStateCallbackDeathRecipient(std::weak_ptr<AppMgrServiceInner> appMgrServiceInner)
73 : appMgrServiceInner_(appMgrServiceInner) {}
74
OnRemoteDied(const wptr<IRemoteObject> & remote)75 void AppStateCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
76 {
77 auto appMgrInner = appMgrServiceInner_.lock();
78 if (appMgrInner) {
79 appMgrInner->RemoveDeadAppStateCallback(remote);
80 }
81 }
82 } // namespace AppExecFwk
83 } // namespace OHOS
84