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 #include "form_constants.h"
19 #include "form_mgr_errors.h"
20 #include "form_supply_callback.h"
21 #include "form_task_mgr.h"
22 #include "hilog_wrapper.h"
23 #include "want.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
FormShareConnection(int64_t formId,const std::string & bundleName,const std::string & abilityName,const std::string & deviceId,int64_t formShareRequestCode)27 FormShareConnection::FormShareConnection(int64_t formId, const std::string &bundleName,
28 const std::string &abilityName, const std::string &deviceId, int64_t formShareRequestCode)
29 :formId_(formId), remoteDeviceId_(deviceId), formShareRequestCode_(formShareRequestCode)
30 {
31 SetProviderKey(bundleName, abilityName);
32 }
33
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int32_t resultCode)34 void FormShareConnection::OnAbilityConnectDone(
35 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
36 {
37 HILOG_DEBUG("%{public}s called.", __func__);
38 if (resultCode != ERR_OK) {
39 HILOG_ERROR("%{public}s, abilityName:%{public}s, resultCode:%{public}d",
40 __func__, element.GetAbilityName().c_str(), resultCode);
41 FormTaskMgr::GetInstance().PostFormShareSendResponse(formShareRequestCode_,
42 ERR_APPEXECFWK_FORM_BIND_PROVIDER_FAILED);
43 return;
44 }
45
46 FormSupplyCallback::GetInstance()->AddConnection(this);
47 Want want;
48 want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
49 want.SetParam(Constants::FORM_SHARE_REQUEST_CODE, formShareRequestCode_);
50
51 FormTaskMgr::GetInstance().PostShareAcquireTask(formId_, remoteDeviceId_, want, remoteObject);
52 }
53 } // namespace AppExecFwk
54 } // namespace OHOS
55