• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021-2022 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 "form_provider/connection/form_refresh_connection.h"
18 
19 #include <cinttypes>
20 
21 #include "fms_log_wrapper.h"
22 #include "form_constants.h"
23 #include "form_provider/form_supply_callback.h"
24 #include "form_provider/form_provider_task_mgr.h"
25 #include "data_center/form_data_mgr.h"
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
FormRefreshConnection(const int64_t formId,const Want & want,const std::string & bundleName,const std::string & abilityName,bool isFreeInstall)30 FormRefreshConnection::FormRefreshConnection(const int64_t formId, const Want& want,
31     const std::string &bundleName, const std::string &abilityName, bool isFreeInstall)
32     : want_(want)
33 {
34     SetFormId(formId);
35     SetFreeInstall(isFreeInstall);
36     SetProviderKey(bundleName, abilityName);
37 }
38 
39 /**
40  * @brief OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
41  *
42  * @param element Service ability's ElementName.
43  * @param remoteObject The session proxy of service ability.
44  * @param resultCode ERR_OK on success, others on failure.
45  */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)46 void FormRefreshConnection::OnAbilityConnectDone(
47     const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
48 {
49     HILOG_INFO("call, formId:%{public}" PRId64, GetFormId());
50     FormAbilityConnection::OnAbilityConnectDone(element, remoteObject, resultCode);
51     if (resultCode != ERR_OK) {
52         HILOG_ERROR("abilityName:%{public}s, formId:%{public}" PRId64 ", resultCode:%{public}d",
53             element.GetAbilityName().c_str(), GetFormId(), resultCode);
54         return;
55     }
56     onFormAppConnect();
57     sptr<FormRefreshConnection> connection(this);
58     FormSupplyCallback::GetInstance()->AddConnection(connection);
59 
60     if (want_.HasParameter(Constants::PARAM_MESSAGE_KEY)) {
61         std::string message = want_.GetStringParam(Constants::PARAM_MESSAGE_KEY);
62         Want msgWant = Want(want_);
63         msgWant.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
64         FormProviderTaskMgr::GetInstance().PostFormEventTask(GetFormId(), message, msgWant, remoteObject);
65     } else if (want_.HasParameter(Constants::RECREATE_FORM_KEY)) {
66         Want cloneWant = Want(want_);
67         cloneWant.RemoveParam(Constants::RECREATE_FORM_KEY);
68         cloneWant.SetParam(Constants::ACQUIRE_TYPE, Constants::ACQUIRE_TYPE_RECREATE_FORM);
69         cloneWant.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
70         FormProviderTaskMgr::GetInstance().PostAcquireTask(GetFormId(), cloneWant, remoteObject);
71     } else {
72         Want want = Want(want_);
73         want.SetParam(Constants::FORM_CONNECT_ID, this->GetConnectId());
74         FormProviderTaskMgr::GetInstance().PostRefreshTask(GetFormId(), want, remoteObject);
75         FormDataMgr::GetInstance().ClearHostRefreshFlag(GetFormId());
76     }
77 }
78 }  // namespace AppExecFwk
79 }  // namespace OHOS