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_delete_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 "want.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
FormDeleteConnection(const int64_t formId,const std::string & bundleName,const std::string & abilityName)28 FormDeleteConnection::FormDeleteConnection(const int64_t formId, const std::string &bundleName,
29     const std::string &abilityName)
30 {
31     SetFormId(formId);
32     SetProviderKey(bundleName, abilityName);
33 }
34 /**
35  * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
36  * @param element service ability's ElementName.
37  * @param remoteObject the session proxy of service ability.
38  * @param resultCode ERR_OK on success, others on failure.
39  */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)40 void FormDeleteConnection::OnAbilityConnectDone(
41     const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
42 {
43     HILOG_INFO("call");
44     if (resultCode != ERR_OK) {
45         HILOG_ERROR("abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d",
46             element.GetAbilityName().c_str(), GetFormId(), resultCode);
47         return;
48     }
49     onFormAppConnect();
50     sptr<FormDeleteConnection> connection(this);
51     FormSupplyCallback::GetInstance()->AddConnection(connection);
52 
53     Want want;
54     want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
55     HILOG_DEBUG("connectId:%{public}d", this->GetConnectId());
56     FormTaskMgr::GetInstance().PostDeleteTask(GetFormId(), want, remoteObject);
57 }
58 }  // namespace AppExecFwk
59 }  // namespace OHOS