• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_acquire_connection.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 "hilog_wrapper.h"
26 #include "ipc_types.h"
27 #include "message_parcel.h"
28 #include "want.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
FormAcquireConnection(const int64_t formId,const FormItemInfo & info,const WantParams & wantParams)32 FormAcquireConnection::FormAcquireConnection(
33     const int64_t formId,
34     const FormItemInfo &info,
35     const WantParams &wantParams)
36     :formId_(formId),
37     info_(info),
38     wantParams_(wantParams)
39 {
40     SetProviderKey(info.GetProviderBundleName(), info.GetAbilityName());
41 }
42 /**
43  * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
44  * @param element service ability's ElementName.
45  * @param remoteObject the session proxy of service ability.
46  * @param resultCode ERR_OK on success, others on failure.
47  */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)48 void FormAcquireConnection::OnAbilityConnectDone(
49     const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
50 {
51     HILOG_INFO("%{public}s called.", __func__);
52 
53     if (resultCode != ERR_OK) {
54         HILOG_ERROR("%{public}s, abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d",
55            __func__, element.GetAbilityName().c_str(), formId_, resultCode);
56         return;
57     }
58     FormSupplyCallback::GetInstance()->AddConnection(this);
59     Want want;
60     want.SetParams(wantParams_);
61     FormUtil::CreateFormWant(info_.GetFormName(), info_.GetSpecificationId(), info_.IsTemporaryForm(), want);
62     if (want.GetBoolParam(Constants::RECREATE_FORM_KEY, false)) {
63         want.SetParam(Constants::ACQUIRE_TYPE, Constants::ACQUIRE_TYPE_RECREATE_FORM);
64     } else {
65         want.SetParam(Constants::ACQUIRE_TYPE, Constants::ACQUIRE_TYPE_CREATE_FORM);
66     }
67     want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
68     want.SetElementName(info_.GetDeviceId(), info_.GetProviderBundleName(),  info_.GetAbilityName());
69     HILOG_INFO("%{public}s , deviceId: %{public}s, bundleName: %{public}s, abilityName: %{public}s.",
70         __func__, info_.GetDeviceId().c_str(), info_.GetProviderBundleName().c_str(), info_.GetAbilityName().c_str());
71 
72     FormTaskMgr::GetInstance().PostAcquireTask(formId_, want, remoteObject);
73 }
74 }  // namespace AppExecFwk
75 }  // namespace OHOS