1 /*
2  * Copyright (c) 2021-2023 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 #ifndef OHOS_FORM_FWK_FORM_PROVIDER_PROXY_H
17 #define OHOS_FORM_FWK_FORM_PROVIDER_PROXY_H
18 
19 #include "fms_log_wrapper.h"
20 #include "form_provider_interface.h"
21 #include "iremote_proxy.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 /**
26  * @class FormProviderProxy
27  * FormProviderProxy is used to access form provider service.
28  */
29 class FormProviderProxy : public IRemoteProxy<IFormProvider> {
30 public:
FormProviderProxy(const sptr<IRemoteObject> & impl)31     explicit FormProviderProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFormProvider>(impl)
32     {}
33 
34     virtual ~FormProviderProxy() = default;
35 
36     /**
37      * @brief Acquire to give back an ProviderFormInfo. This is sync API.
38      * @param formJsInfo The form js info.
39      * @param want Indicates the {@link Want} structure containing form info.
40      * @param callerToken Caller ability token.
41      * @return Returns ERR_OK on success, others on failure.
42      */
43     virtual int AcquireProviderFormInfo(const FormJsInfo &formJsInfo, const Want &want,
44     const sptr<IRemoteObject> &callerToken) override;
45 
46     /**
47      * @brief Notify provider when the form was deleted.
48      * @param formId The Id of the form.
49      * @param want Indicates the structure containing form info.
50      * @param callerToken Caller ability token.
51      * @return Returns ERR_OK on success, others on failure.
52      */
53     virtual int NotifyFormDelete(const int64_t formId, const Want &want,
54     const sptr<IRemoteObject> &callerToken) override;
55 
56     /**
57      * @brief Notify provider when the forms was deleted.
58      * @param formIds The id list of forms.
59      * @param want Indicates the structure containing form info.
60      * @param callerToken Caller ability token.
61      * @return Returns ERR_OK on success, others on failure.
62      */
63     virtual int NotifyFormsDelete(const std::vector<int64_t> &formIds, const Want &want,
64     const sptr<IRemoteObject> &callerToken) override;
65 
66     /**
67      * @brief Notify provider when the form need update.
68      * @param formId The Id of the form.
69      * @param want Indicates the structure containing form info.
70      * @param callerToken Caller ability token.
71      * @return Returns ERR_OK on success, others on failure.
72      */
73     virtual int NotifyFormUpdate(const int64_t formId, const Want &want,
74     const sptr<IRemoteObject> &callerToken) override;
75 
76     /**
77      * @brief Event notify when change the form visible.
78      *
79      * @param formIds The vector of form ids.
80      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
81      * @param want Indicates the structure containing form info.
82      * @param callerToken Caller ability token.
83      * @return Returns ERR_OK on success, others on failure.
84      */
85     virtual int EventNotify(const std::vector<int64_t> &formIds, const int32_t formVisibleType,
86         const Want &want, const sptr<IRemoteObject> &callerToken) override;
87 
88     /**
89      * @brief Notify provider when the temp form was cast to normal form.
90      * @param formId The Id of the form to update.
91      * @param want Indicates the structure containing form info.
92      * @param callerToken Caller ability token.
93      * @return Returns ERR_OK on success, others on failure.
94      */
95     virtual int NotifyFormCastTempForm(const int64_t formId, const Want &want,
96     const sptr<IRemoteObject> &callerToken) override;
97     /**
98      * @brief Fire message event to form provider.
99      * @param formId The Id of the from.
100      * @param message Event message.
101      * @param want The want of the request.
102      * @param callerToken Form provider proxy object.
103      * @return Returns ERR_OK on success, others on failure.
104      */
105     virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
106     const sptr<IRemoteObject> &callerToken) override;
107 
108     /**
109      * @brief Acquire form state to form provider.
110      * @param wantArg The want of onAcquireFormState.
111      * @param provider The provider info.
112      * @param want The want of the request.
113      * @param callerToken Form provider proxy object.
114      * @return Returns ERR_OK on success, others on failure.
115      */
116     virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
117                              const sptr<IRemoteObject> &callerToken) override;
118 
119     /**
120      * @brief Acquire to share form information data. This is sync API.
121      * @param formId The Id of the from.
122      * @param remoteDeviceId Indicates the remote device ID.
123      * @param formSupplyCallback Indicates lifecycle callbacks.
124      * @param requestCode Indicates the request code of this share form.
125      * @return Returns ERR_OK on success, others on failure.
126      */
127     int32_t AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
128         const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode) override;
129 
130     /**
131      * @brief Acquire to form data.
132      * @param formId The Id of the from.
133      * @param formSupplyCallback Indicates lifecycle callbacks.
134      * @param requestCode Indicates the request code of this share form.
135      * @return Returns ERR_OK on success, others on failure.
136      */
137     int32_t AcquireFormData(int64_t formId, const sptr<IRemoteObject> &formSupplyCallback,
138                             int64_t requestCode) override;
139 
140 private:
141     template<typename T>
142     int GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos);
143     bool WriteInterfaceToken(MessageParcel &data);
144     int SendTransactCmd(IFormProvider::Message code, MessageParcel &data,
145         MessageParcel &reply, MessageOption &option);
146 
147 private:
148     static inline BrokerDelegator<FormProviderProxy> delegator_;
149 };
150 }  // namespace AppExecFwk
151 }  // namespace OHOS
152 #endif  // OHOS_FORM_FWK_FORM_PROVIDER_PROXY_H
153