1 
2 /*
3  * Copyright (c) 2022 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "form_share_connection.h"
18 
19 #include "fms_log_wrapper.h"
20 #include "form_constants.h"
21 #include "form_mgr_errors.h"
22 #include "form_supply_callback.h"
23 #include "form_task_mgr.h"
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
FormShareConnection(int64_t formId,const std::string & bundleName,const std::string & abilityName,const std::string & deviceId,int64_t formShareRequestCode)28 FormShareConnection::FormShareConnection(int64_t formId, const std::string &bundleName,
29     const std::string &abilityName, const std::string &deviceId, int64_t formShareRequestCode)
30     :formId_(formId), remoteDeviceId_(deviceId), formShareRequestCode_(formShareRequestCode)
31 {
32     SetProviderKey(bundleName, abilityName);
33 }
34 
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)35 void FormShareConnection::OnAbilityConnectDone(
36     const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
37 {
38     HILOG_DEBUG("call");
39     if (resultCode != ERR_OK) {
40         HILOG_ERROR("abilityName:%{public}s, resultCode:%{public}d",
41             element.GetAbilityName().c_str(), resultCode);
42         FormTaskMgr::GetInstance().PostFormShareSendResponse(formShareRequestCode_,
43             ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED);
44         return;
45     }
46     onFormAppConnect();
47     sptr<FormShareConnection> connection(this);
48     FormSupplyCallback::GetInstance()->AddConnection(connection);
49     Want want;
50     want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
51     want.SetParam(Constants::FORM_SHARE_REQUEST_CODE, formShareRequestCode_);
52 
53     FormTaskMgr::GetInstance().PostShareAcquireTask(formId_, remoteDeviceId_, want, remoteObject);
54 }
55 } // namespace AppExecFwk
56 } // namespace OHOS
57