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_acquire_data_connection.h"
17
18 #include <cinttypes>
19
20 #include "fms_log_wrapper.h"
21 #include "form_constants.h"
22 #include "form_supply_callback.h"
23 #include "form_task_mgr.h"
24 #include "form_util.h"
25 #include "want.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
FormAcquireDataConnection(const int64_t formId,const std::string & bundleName,const std::string & abilityName,int64_t formRequestCode)29 FormAcquireDataConnection::FormAcquireDataConnection(const int64_t formId, const std::string &bundleName,
30 const std::string &abilityName, int64_t formRequestCode) : formRequestCode_(formRequestCode)
31 {
32 SetFormId(formId);
33 SetProviderKey(bundleName, abilityName);
34 }
35
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)36 void FormAcquireDataConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
37 const sptr<IRemoteObject> &remoteObject, int resultCode)
38 {
39 HILOG_DEBUG("call");
40 if (resultCode != ERR_OK) {
41 HILOG_ERROR("abilityName:%{public}s, resultCode:%{public}d",
42 element.GetAbilityName().c_str(), resultCode);
43 return;
44 }
45 onFormAppConnect();
46 sptr<FormAcquireDataConnection> connection(this);
47 FormSupplyCallback::GetInstance()->AddConnection(connection);
48 Want want;
49 want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
50 want.SetParam(Constants::FORM_ACQUIRE_DATA_REQUEST_CODE, formRequestCode_);
51 FormTaskMgr::GetInstance().PostAcquireDataTask(GetFormId(), want, remoteObject);
52 }
53 } // namespace AppExecFwk
54 } // namespace OHOS