1
2 /*
3 * Copyright (c) 2021 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 "appexecfwk_errors.h"
18 #include "form_constants.h"
19 #include "form_event_notify_connection.h"
20 #include "form_supply_callback.h"
21 #include "form_task_mgr.h"
22 #include "hilog_wrapper.h"
23 #include "ipc_types.h"
24 #include "message_parcel.h"
25 #include "want.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
FormEventNotifyConnection(const std::vector<int64_t> formEvents,const int32_t formVisibleType,const std::string & bundleName,const std::string & abilityName)29 FormEventNotifyConnection::FormEventNotifyConnection(const std::vector<int64_t> formEvents,
30 const int32_t formVisibleType, const std::string &bundleName, const std::string &abilityName)
31 :formEvents_(formEvents),
32 formVisibleType_(formVisibleType)
33 {
34 SetProviderKey(bundleName, abilityName);
35 }
36 /**
37 * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
38 *
39 * @param element Service ability's ElementName.
40 * @param remoteObject The session proxy of service ability.
41 * @param resultCode ERR_OK on success, others on failure.
42 * @return none.
43 */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)44 void FormEventNotifyConnection::OnAbilityConnectDone(
45 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
46 {
47 HILOG_INFO("%{public}s called.", __func__);
48 if (resultCode != ERR_OK) {
49 HILOG_ERROR("%{public}s, abilityName:%{public}s, resultCode:%{public}d",
50 __func__, element.GetAbilityName().c_str(), resultCode);
51 return;
52 }
53 FormSupplyCallback::GetInstance()->AddConnection(this);
54
55 Want want;
56 want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
57 FormTaskMgr::GetInstance().PostEventNotifyTask(formEvents_, formVisibleType_, want, remoteObject);
58 }
59 } // namespace AppExecFwk
60 } // namespace OHOS