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) : formId_(formId), formRequestCode_(formRequestCode)
31 {
32 SetProviderKey(bundleName, abilityName);
33 }
34
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)35 void FormAcquireDataConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
36 const sptr<IRemoteObject> &remoteObject, int resultCode)
37 {
38 HILOG_DEBUG("called.");
39 if (resultCode != ERR_OK) {
40 HILOG_ERROR("abilityName:%{public}s, resultCode:%{public}d",
41 element.GetAbilityName().c_str(), resultCode);
42 return;
43 }
44
45 sptr<FormAcquireDataConnection> connection(this);
46 FormSupplyCallback::GetInstance()->AddConnection(connection);
47 Want want;
48 want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
49 want.SetParam(Constants::FORM_ACQUIRE_DATA_REQUEST_CODE, formRequestCode_);
50 FormTaskMgr::GetInstance().PostAcquireDataTask(formId_, want, remoteObject);
51 }
52 } // namespace AppExecFwk
53 } // namespace OHOS