• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "aafwk_app_mgr_client_adapter_impl.h"
17 
18 #include "aafwk_render_scheduler_impl.h"
19 #include "nweb_log.h"
20 
21 namespace {
22 constexpr int GET_TERMINATION_STATUS_MAX_CNT = 5;
23 }
24 
25 namespace OHOS::NWeb {
AafwkAppMgrClientAdapterImpl()26 AafwkAppMgrClientAdapterImpl::AafwkAppMgrClientAdapterImpl() :
27     appMgrClient_(std::make_unique<AppExecFwk::AppMgrClient>()) {}
28 
StartRenderProcess(const std::string & renderParam,int32_t ipcFd,int32_t sharedFd,pid_t & renderPid)29 int AafwkAppMgrClientAdapterImpl::StartRenderProcess(const std::string &renderParam, int32_t ipcFd,
30     int32_t sharedFd, pid_t &renderPid)
31 {
32     if (appMgrClient_ == nullptr) {
33         WVLOG_E("app mgr client is nullptr.");
34         return -1;
35     }
36 
37     int ret = appMgrClient_->StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid);
38     if (ret != 0) {
39         WVLOG_E("app mgr client start render process failed, ret = %{public}d.", ret);
40         return -1;
41     }
42 
43     return 0;
44 }
45 
AttachRenderProcess(std::shared_ptr<AafwkRenderSchedulerHostAdapter> adapter)46 void AafwkAppMgrClientAdapterImpl::AttachRenderProcess(std::shared_ptr<AafwkRenderSchedulerHostAdapter> adapter)
47 {
48     if (appMgrClient_ == nullptr) {
49         WVLOG_E("app mgr client is nullptr.");
50         return;
51     }
52 
53     if (adapter == nullptr) {
54         WVLOG_E("render scheduler is nullptr.");
55         return;
56     }
57 
58     AafwkRenderSchedulerImpl *renderScheduler = new (std::nothrow) AafwkRenderSchedulerImpl(adapter);
59     if (renderScheduler == nullptr) {
60         WVLOG_E("new AafwkRenderSchedulerImpl failed.");
61         return;
62     }
63 
64     appMgrClient_->AttachRenderProcess(renderScheduler);
65 }
66 
GetRenderProcessTerminationStatus(pid_t renderPid,int & status)67 int AafwkAppMgrClientAdapterImpl::GetRenderProcessTerminationStatus(pid_t renderPid, int &status)
68 {
69     if (appMgrClient_ == nullptr) {
70         WVLOG_E("app mgr client is nullptr.");
71         return -1;
72     }
73 
74     int retryCnt = 0;
75     do {
76         int ret = appMgrClient_->GetRenderProcessTerminationStatus(renderPid, status);
77         if (ret != 0) {
78             WVLOG_E("app mgr client get render process termination status failed, ret = %{public}d.", ret);
79             return -1;
80         }
81     } while (status < 0 && ++retryCnt < GET_TERMINATION_STATUS_MAX_CNT);
82 
83     if (status < 0) {
84         WVLOG_E("render process termination status invalid, status = %{public}d.", status);
85         return -1;
86     }
87 
88     return 0;
89 }
90 }  // namespace OHOS::NWeb
91