1 /*
2 * Copyright (c) 2021-2022 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_host_callback.h"
17
18 #include <cinttypes>
19
20 #include "form_host_interface.h"
21 #include "form_task_mgr.h"
22 #include "hilog_wrapper.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 /**
27 * @brief Request to give back a Form.
28 * @param formId The Id of the forms to create.
29 * @param record Form record.
30 * @param callerToken Caller ability token.
31 */
OnAcquired(const int64_t formId,const FormRecord & record,const sptr<IRemoteObject> & callerToken)32 void FormHostCallback::OnAcquired(const int64_t formId, const FormRecord& record,
33 const sptr<IRemoteObject> &callerToken)
34 {
35 HILOG_DEBUG("FormHostCallback OnAcquired, formId:%{public}" PRId64 "", formId);
36 FormTaskMgr::GetInstance().PostAcquireTaskToHost(formId, record, callerToken);
37 }
38
39 /**
40 * @brief Form is updated.
41 * @param formId The Id of the form to update.
42 * @param record Form record.
43 * @param callerToken Caller ability token.
44 */
OnUpdate(const int64_t formId,const FormRecord & record,const sptr<IRemoteObject> & callerToken)45 void FormHostCallback::OnUpdate(const int64_t formId, const FormRecord &record, const sptr<IRemoteObject> &callerToken)
46 {
47 HILOG_INFO("%{public}s start.", __func__);
48
49 // check formId
50 if (formId < 0) {
51 HILOG_ERROR("%{public}s: OnUpdate invalid param, formId:%{public}" PRId64 ".", __func__, formId);
52 return;
53 }
54
55 if (callerToken == nullptr) {
56 HILOG_ERROR("%{public}s: callerToken can not be NULL", __func__);
57 return;
58 }
59
60 // post updateTask to host
61 FormTaskMgr::GetInstance().PostUpdateTaskToHost(formId, record, callerToken);
62 }
63
64 /**
65 * @brief Form provider is uninstalled
66 * @param formIds The Id list of the forms.
67 * @param callerToken Caller ability token.
68 */
OnUninstall(std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken)69 void FormHostCallback::OnUninstall(std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken)
70 {
71 // check formId
72 if (formIds.empty()) {
73 HILOG_ERROR("%{public}s: OnUninstall invalid param, formIds is empty.", __func__);
74 return;
75 }
76
77 if (callerToken == nullptr) {
78 HILOG_ERROR("%{public}s: callerToken can not be NULL", __func__);
79 return;
80 }
81 // post updateTask to host
82 FormTaskMgr::GetInstance().PostUninstallTaskToHost(formIds, callerToken);
83 }
84
85 /**
86 * @brief Form provider is uninstalled.
87 * @param state The form state.
88 * @param want The want of onAcquireFormState.
89 * @param callerToken Caller ability token.
90 */
OnAcquireState(AppExecFwk::FormState state,const AAFwk::Want & want,const sptr<IRemoteObject> & callerToken)91 void FormHostCallback::OnAcquireState(AppExecFwk::FormState state, const AAFwk::Want &want,
92 const sptr<IRemoteObject> &callerToken)
93 {
94 if (callerToken == nullptr) {
95 HILOG_ERROR("%{public}s: callerToken can not be NULL", __func__);
96 return;
97 }
98 // post updateTask to host
99 FormTaskMgr::GetInstance().PostAcquireStateTaskToHost(state, want, callerToken);
100 }
101 } // namespace AppExecFwk
102 } // namespace OHOS
103