• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "form_render_connection.h"
17 
18 #include <cinttypes>
19 
20 #include "form_bms_helper.h"
21 #include "form_constants.h"
22 #include "form_mgr_errors.h"
23 #include "form_supply_callback.h"
24 #include "form_render_mgr.h"
25 #include "form_task_mgr.h"
26 #include "form_util.h"
27 #include "hilog_wrapper.h"
28 #include "ipc_skeleton.h"
29 #include "want.h"
30 
31 namespace OHOS {
32 namespace AppExecFwk {
FormRenderConnection(const FormRecord & formRecord,const WantParams & wantParams)33 FormRenderConnection::FormRenderConnection(
34     const FormRecord &formRecord, const WantParams &wantParams) : formRecord_(formRecord), wantParams_(wantParams)
35 {
36     SetFormId(formRecord.formId);
37     SetProviderKey(formRecord.bundleName, formRecord.abilityName);
38 }
39 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)40 void FormRenderConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
41     const sptr<IRemoteObject> &remoteObject, int resultCode)
42 {
43     HILOG_INFO("ConnectDone");
44     if (resultCode != ERR_OK) {
45         HILOG_ERROR("%{public}s, abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d",
46            __func__, element.GetAbilityName().c_str(), GetFormId(), resultCode);
47         return;
48     }
49 
50     connectState_ = ConnectState::CONNECTED;
51     int32_t compileMode = 0;
52     if (!FormBmsHelper::GetInstance().GetCompileMode(formRecord_.bundleName, formRecord_.moduleName,
53         FormUtil::GetCurrentAccountId(), compileMode)) {
54         HILOG_ERROR("get compile mode failed.");
55         return;
56     }
57 
58     int32_t compatibleVersionCode = 0;
59     if (!FormBmsHelper::GetInstance().GetCompatibleVersionCode(
60             formRecord_.bundleName, FormUtil::GetCurrentAccountId(), compatibleVersionCode)) {
61         HILOG_ERROR("get compatible version code failed.");
62         return;
63     }
64 
65     FormRenderMgr::GetInstance().AddConnection(GetFormId(), this);
66     FormRenderMgr::GetInstance().AddRenderDeathRecipient(remoteObject);
67     Want want;
68     want.SetParams(wantParams_);
69     want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
70     want.SetParam(Constants::FORM_COMPILE_MODE_KEY, compileMode);
71     want.SetParam(Constants::FORM_COMPATIBLE_VERSION_CODE_KEY, compatibleVersionCode);
72     FormTaskMgr::GetInstance().PostRenderForm(formRecord_, std::move(want), remoteObject);
73 }
74 
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)75 void FormRenderConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
76 {
77     HILOG_DEBUG("element:%{public}s, resultCode:%{public}d, connectState: %{public}d",
78         element.GetURI().c_str(), resultCode, connectState_);
79     // If connectState_ is CONNECTING, it means connect failed, need to notify host
80     if (resultCode && connectState_ == ConnectState::CONNECTING) {
81         FormRenderMgr::GetInstance().HandleConnectFailed(
82             formRecord_.formId, ERR_APPEXECFWK_FORM_CONNECT_FORM_RENDER_FAILED);
83     }
84     connectState_ = ConnectState::DISCONNECTED;
85 }
86 
SetStateConnecting()87 void FormRenderConnection::SetStateConnecting()
88 {
89     connectState_ = ConnectState::CONNECTING;
90 }
91 
SetStateDisconnected()92 void FormRenderConnection::SetStateDisconnected()
93 {
94     connectState_ = ConnectState::DISCONNECTED;
95 }
96 
UpdateWantParams(const WantParams & wantParams)97 void FormRenderConnection::UpdateWantParams(const WantParams &wantParams)
98 {
99     wantParams_ = wantParams;
100 }
101 }  // namespace AppExecFwk
102 }  // namespace OHOS
103