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 <cinttypes>
18
19 #include "appexecfwk_errors.h"
20 #include "form_ability_connection.h"
21 #include "form_supply_callback.h"
22 #include "form_task_mgr.h"
23 #include "hilog_wrapper.h"
24 #include "ipc_types.h"
25 #include "message_parcel.h"
26 #include "want.h"
27
28 namespace OHOS {
29 namespace AppExecFwk {
30 /**
31 * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
32 * @param element service ability's ElementName.
33 * @param remoteObject the session proxy of service ability.
34 * @param resultCode ERR_OK on success, others on failure.
35 */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)36 void FormAbilityConnection::OnAbilityConnectDone(
37 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
38 {
39 if (resultCode != ERR_OK) {
40 HILOG_ERROR("%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d",
41 __func__, formId_, resultCode);
42 return;
43 }
44
45 if (isFreeInstall_) {
46 // Handle free install for form provider app
47 HILOG_INFO("%{public}s current is Free Install.", __func__);
48 }
49 }
50
51 /**
52 * @brief OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect.
53 * @param element service ability's ElementName.
54 * @param resultCode ERR_OK on success, others on failure.
55 */
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)56 void FormAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
57 {
58 HILOG_DEBUG(
59 "%{public}s, element:%{public}s, resultCode:%{public}d", __func__, element.GetURI().c_str(), resultCode);
60 if (connectId_ != 0) {
61 FormSupplyCallback::GetInstance()->RemoveConnection(connectId_);
62 connectId_ = 0;
63 } else {
64 HILOG_ERROR("%{public}s fail, connectId_ invalidate. connectId_: %{public}ld", __func__, connectId_);
65 }
66 }
67
68 /**
69 * @brief Remote object died event.
70 * @param remoteObject the remote object of service ability.
71 */
OnConnectDied(const wptr<IRemoteObject> & remoteObject)72 void FormAbilityConnection::OnConnectDied(const wptr<IRemoteObject> &remoteObject)
73 {
74 if (connectId_ != 0) {
75 FormSupplyCallback::GetInstance()->RemoveConnection(connectId_);
76 connectId_ = 0;
77 } else {
78 HILOG_ERROR("%{public}s fail, connectId_ invalidate. connectId_: %{public}ld", __func__, connectId_);
79 }
80 }
81
82 /**
83 * @brief Set connectId.
84 * @param connectId The ability connection id.
85 */
SetConnectId(long connectId)86 void FormAbilityConnection::SetConnectId(long connectId)
87 {
88 HILOG_INFO("%{public}s, connectId_: %{public}ld", __func__, connectId);
89 connectId_ = connectId;
90 }
91
92 /**
93 * @brief Get connectId.
94 * @return The ability connection id.
95 */
GetConnectId()96 long FormAbilityConnection::GetConnectId()
97 {
98 return connectId_;
99 }
100
101 /**
102 * @brief Get the provider Key
103 *
104 * @return The provider Key
105 */
GetProviderKey()106 std::string FormAbilityConnection::GetProviderKey()
107 {
108 if (bundleName_.empty() || abilityName_.empty()) {
109 return "";
110 }
111 return bundleName_ + "::" + abilityName_;
112 }
113
114 /**
115 * @brief Set the Provider Key
116 *
117 * @param bundleName bundleName
118 * @param abilityName abilityName
119 */
SetProviderKey(const std::string & bundleName,const std::string & abilityName)120 void FormAbilityConnection::SetProviderKey(const std::string &bundleName, const std::string &abilityName)
121 {
122 bundleName_ = bundleName;
123 abilityName_ = abilityName;
124 }
125 } // namespace AppExecFwk
126 } // namespace OHOS