• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "app_death_recipient.h"
17 
18 #include "app_log_wrapper.h"
19 #include "app_mgr_service_inner.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 const std::string TASK_ON_REMOTE_DIED = "OnRemoteDiedTask";
25 }
26 
OnRemoteDied(const wptr<IRemoteObject> & remote)27 void AppDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
28 {
29     if (remote == nullptr) {
30         APP_LOGE("remote is null");
31         return;
32     }
33 
34     auto handler = handler_.lock();
35     if (!handler) {
36         APP_LOGE("handler is null");
37         return;
38     }
39     auto serviceInner = appMgrServiceInner_.lock();
40     if (!serviceInner) {
41         APP_LOGE("serviceInner is null");
42         return;
43     }
44 
45     std::function <void()> onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote);
46     handler->PostTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED);
47 }
48 
SetEventHandler(const std::shared_ptr<AMSEventHandler> & handler)49 void AppDeathRecipient::SetEventHandler(const std::shared_ptr<AMSEventHandler> &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 }  // namespace AppExecFwk
59 }  // namespace OHOS
60