1 /*
2 * Copyright (c) 2021-2022 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_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 HILOG_ERROR("remote is null");
30 return;
31 }
32
33 auto handler = handler_.lock();
34 if (!handler) {
35 HILOG_ERROR("handler is null");
36 return;
37 }
38 auto serviceInner = appMgrServiceInner_.lock();
39 if (!serviceInner) {
40 HILOG_ERROR("serviceInner is null");
41 return;
42 }
43
44 auto onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote, isRenderProcess_,
45 isChildProcess_);
46 handler->SubmitTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED);
47 }
48
SetTaskHandler(const std::shared_ptr<AAFwk::TaskHandlerWrap> & handler)49 void AppDeathRecipient::SetTaskHandler(const std::shared_ptr<AAFwk::TaskHandlerWrap> &handler)
50 {
51 handler_ = handler;
52 }
53
SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> & serviceInner)54 void AppDeathRecipient::SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> &serviceInner)
55 {
56 appMgrServiceInner_ = serviceInner;
57 }
58
SetIsRenderProcess(bool isRenderProcess)59 void AppDeathRecipient::SetIsRenderProcess(bool isRenderProcess)
60 {
61 isRenderProcess_ = isRenderProcess;
62 }
63
SetIsChildProcess(bool isChildProcess)64 void AppDeathRecipient::SetIsChildProcess(bool isChildProcess)
65 {
66 isChildProcess_ = isChildProcess;
67 }
68 } // namespace AppExecFwk
69 } // namespace OHOS
70