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)26void 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 handler->PostTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); 46 } 47 SetEventHandler(const std::shared_ptr<AMSEventHandler> & handler)48void AppDeathRecipient::SetEventHandler(const std::shared_ptr<AMSEventHandler> &handler) 49 { 50 handler_ = handler; 51 } 52 SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> & serviceInner)53void AppDeathRecipient::SetAppMgrServiceInner(const std::shared_ptr<AppMgrServiceInner> &serviceInner) 54 { 55 appMgrServiceInner_ = serviceInner; 56 } 57 SetIsRenderProcess(bool isRenderProcess)58void AppDeathRecipient::SetIsRenderProcess(bool isRenderProcess) 59 { 60 isRenderProcess_ = isRenderProcess; 61 } 62 } // namespace AppExecFwk 63 } // namespace OHOS 64