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 SMS_SERVICE_PROXY_H
17#define SMS_SERVICE_PROXY_H
18
19#include "i_sms_service_interface.h"
20
21#include "iremote_object.h"
22#include "iremote_proxy.h"
23#include "sms_service_ipc_interface_code.h"
24
25namespace OHOS {
26namespace Telephony {
27class SmsServiceProxy : public IRemoteProxy<ISmsServiceInterface> {
28public:
29    explicit SmsServiceProxy(const sptr<IRemoteObject> &impl);
30    virtual ~SmsServiceProxy() = default;
31
32    /**
33     * @brief SendMessage
34     * Sends a text or data SMS message.
35     * @param slotId [in]
36     * @param desAddr [in]
37     * @param scAddr [in]
38     * @param text [in]
39     * @param sendCallback [in]
40     * @param deliverCallback [in]
41     * @return int32_t
42     */
43    int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
44        const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback,
45        const sptr<IDeliveryShortMessageCallback> &deliverCallback, bool isMmsApp = true) override;
46
47    /**
48     * @brief SendMessageWithoutSave
49     * Sends a text or data SMS message without save to database.
50     * @param slotId [in]
51     * @param desAddr [in]
52     * @param scAddr [in]
53     * @param text [in]
54     * @param sendCallback [in]
55     * @param deliverCallback [in]
56     * @return int32_t
57     */
58    int32_t SendMessageWithoutSave(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
59        const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback,
60        const sptr<IDeliveryShortMessageCallback> &deliverCallback) override;
61
62    /**
63     * @brief SendMessage
64     * Sends a text or data SMS message.
65     * @param slotId [in]
66     * @param desAddr [in]
67     * @param scAddr [in]
68     * @param port [in]
69     * @param data [in]
70     * @param dataLen [in]
71     * @param sendCallback [in]
72     * @param deliverCallback [in].
73     * @return int32_t
74     */
75    int32_t SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr, uint16_t port,
76        const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
77        const sptr<IDeliveryShortMessageCallback> &deliverCallback) override;
78
79    /**
80     * @brief SetSmscAddr
81     * Sets the address for the Short Message Service Center (SMSC) based on a specified slot ID.
82     * @param slotId [in]
83     * @param scAddr [in]
84     * @return int32_t
85     */
86    int32_t SetSmscAddr(int32_t slotId, const std::u16string &scAddr) override;
87
88    /**
89     * @brief GetSmscAddr
90     * Obtains the SMSC address based on a specified slot ID.
91     * @param slotId [in]
92     * @param smscAddress [out]
93     * @return Interface execution results.
94     */
95    int32_t GetSmscAddr(int32_t slotId, std::u16string &smscAddress) override;
96
97    /**
98     * @brief AddSimMessage
99     * Add a sms to sim card.
100     * @param slotId [in]
101     * @param smsc [in]
102     * @param pdu [in]
103     * @param status [in]
104     * @return int32_t
105     */
106    int32_t AddSimMessage(
107        int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, SimMessageStatus status) override;
108
109    /**
110     * @brief DelSimMessage
111     * Delete a sms in the sim card.
112     * @param slotId [in]
113     * @param msgIndex [in]
114     * @return int32_t
115     */
116    int32_t DelSimMessage(int32_t slotId, uint32_t msgIndex) override;
117
118    /**
119     * @brief UpdateSimMessage
120     * Update a sms in the sim card.
121     * @param slotId [in]
122     * @param msgIndex [in]
123     * @param newStatus [in]
124     * @param pdu [in]
125     * @param smsc [in]
126     * @return int32_t
127     */
128    int32_t UpdateSimMessage(int32_t slotId, uint32_t msgIndex, SimMessageStatus newStatus, const std::u16string &pdu,
129        const std::u16string &smsc) override;
130
131    /**
132     * @brief GetAllSimMessages
133     * Get sim card all the sms.
134     * @param slotId [in]
135     * @return int32_t
136     */
137    int32_t GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message) override;
138
139    /**
140     * @brief SetCBConfig
141     * Configure a cell broadcast in a certain band range.
142     * @param slotId [in]
143     * @param enable [in]
144     * @param fromMsgId [in]
145     * @param toMsgId [in]
146     * @param netType [in]
147     * @return true
148     * @return false
149     */
150    int32_t SetCBConfig(int32_t slotId, bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType) override;
151
152    /**
153     * @brief SetImsSmsConfig enable or disable IMS SMS.
154     * @param slotId Indicates the card slot index number,
155     * ranging from {@code 0} to the maximum card slot index number supported by the device.
156     * @param enable Indicates enable or disable Ims sms
157     * ranging {@code 0} disable Ims sms {@code 1} enable Ims sms
158     * @return Returns {@code true} if enable or disable Ims Sms success; returns {@code false} otherwise.
159     */
160    bool SetImsSmsConfig(int32_t slotId, int32_t enable) override;
161
162    /**
163     * @brief SetDefaultSmsSlotId
164     * Set the Default Sms Slot Id To SmsService
165     * @param slotId [in]
166     * @return int32_t
167     */
168    int32_t SetDefaultSmsSlotId(int32_t slotId) override;
169
170    /**
171     * @brief GetDefaultSmsSlotId
172     * Get the Default Sms Slot Id From SmsService
173     * @return int32_t
174     */
175    int32_t GetDefaultSmsSlotId() override;
176
177    /**
178     * Get the Default Sms Sim Id From SmsService
179     */
180    int32_t GetDefaultSmsSimId(int32_t &simId) override;
181
182    /**
183     * @brief SplitMessage
184     * calculate Sms Message Split Segment count
185     * @param message [in]
186     * @return int32_t
187     */
188    int32_t SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage) override;
189
190    /**
191     * @brief GetSmsSegmentsInfo
192     * calculate the Sms Message Segments Info
193     * @param slotId [in]
194     * @param message [in]
195     * @param force7BitCode [in]
196     * @param info [out]
197     * @return Returns {@code 0} if get sms segments info
198     */
199    int32_t GetSmsSegmentsInfo(int32_t slotId, const std::u16string &message, bool force7BitCode,
200        ISmsServiceInterface::SmsSegmentsInfo &segInfo) override;
201
202    /**
203     * Check Sms Is supported Ims newtwork
204     * Hide this for inner system use
205     * @param slotId Indicates the card slot index number, ranging from {@code 0} to the maximum card slot index number
206     * supported by the device.
207     * @param isSupported Whether ims SMS is supported.
208     * @return Interface execution results.
209     */
210    int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override;
211
212    /**
213     * @brief GetImsShortMessageFormat
214     * Get the Ims Short Message Format 3gpp/3gpp2
215     * Hide this for inner system use
216     * @return int32_t
217     */
218    int32_t GetImsShortMessageFormat(std::u16string &format) override;
219
220    /**
221     * @brief HasSmsCapability
222     * Check whether it is supported Sms Capability
223     * @return true
224     * @return false
225     */
226    bool HasSmsCapability() override;
227
228    /**
229     * create a short message
230     * @param pdu Indicates pdu code,
231     * @param specification Indicates 3gpp or 3gpp2
232     * @param ShortMessage Indicates a short message object
233     * @return Returns {@code 0} if CreateMessage success
234     */
235    int32_t CreateMessage(std::string pdu, std::string specification, ShortMessage &message) override;
236
237    /**
238     * mms base64 encode
239     * @param src Indicates source string,
240     * @param dest Indicates destination string
241     * @return Returns {@code true} if encode success; returns {@code false} otherwise
242     */
243    bool GetBase64Encode(std::string src, std::string &dest) override;
244
245    /**
246     * mms base64 decode
247     * @param src Indicates source string,
248     * @param dest Indicates destination string
249     * @return Returns {@code true} if decode success; returns {@code false} otherwise
250     */
251    bool GetBase64Decode(std::string src, std::string &dest) override;
252
253    /**
254     * Get Encode String
255     * @param encodeString Indicates output string,
256     * @param charset Indicates character set,
257     * @param valLength Indicates input string length,
258     * @param strEncodeString Indicates input string
259     * @return Returns {@code true} if decode success; returns {@code false} otherwise
260     */
261    bool GetEncodeStringFunc(
262        std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString) override;
263
264    /**
265     * Send a mms
266     * @param slotId Indicates the card slot index number,
267     * ranging from {@code 0} to the maximum card slot index number supported by the device
268     * @param mmsc Indicates service center of mms
269     * @param data Indicates file path of mms pdu
270     * @param ua Indicates mms user agent
271     * @param uaprof Indicates mms user agent profile
272     * @param time Indicates milliSecond while get Mms call
273     * @param isMmsApp Indicates whether system message hap call this
274     * @return Returns {@code 0} if send mms success; returns {@code false} otherwise
275     */
276    int32_t SendMms(int32_t slotId, const std::u16string &mmsc, const std::u16string &data, const std::u16string &ua,
277        const std::u16string &uaprof, int64_t &time, bool isMmsApp = true) override;
278
279    /**
280     * Download a mms
281     * @param slotId Indicates the card slot index number,
282     * ranging from {@code 0} to the maximum card slot index number supported by the device
283     * @param mmsc Indicates service center of mms
284     * @param ua Indicates mms user agent
285     * @param uaprof Indicates mms user agent profile
286     * @return Returns {@code 0} if download mms success; returns {@code false} otherwise
287     */
288    int32_t DownloadMms(int32_t slotId, const std::u16string &mmsc, std::u16string &data, const std::u16string &ua,
289        const std::u16string &uaprof) override;
290
291private:
292    static inline BrokerDelegator<SmsServiceProxy> delegator_;
293    sptr<IRemoteObject> localObject_;
294};
295
296class SmsServiceDeathRecipient : public IRemoteObject::DeathRecipient {
297public:
298    virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
299    SmsServiceDeathRecipient();
300    virtual ~SmsServiceDeathRecipient();
301    static bool GotDeathRecipient();
302    static bool gotDeathRecipient_;
303};
304} // namespace Telephony
305} // namespace OHOS
306#endif // SMS_SERVICE_PROXY_H
307