• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include "request_service_proxy.h"
16 
17 #include <fcntl.h>
18 #include <sys/stat.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21 
22 #include <cstdint>
23 #include <ctime>
24 #include <optional>
25 
26 #include "constant.h"
27 #include "download_server_ipc_interface_code.h"
28 #include "iremote_broker.h"
29 #include "log.h"
30 #include "message_parcel.h"
31 #include "parcel_helper.h"
32 #include "request_running_task_count.h"
33 #include "sys_event.h"
34 
35 namespace OHOS::Request {
36 using namespace OHOS::HiviewDFX;
37 
RequestServiceProxy(const sptr<IRemoteObject> & object)38 RequestServiceProxy::RequestServiceProxy(const sptr<IRemoteObject> &object)
39     : IRemoteProxy<RequestServiceInterface>(object)
40 {
41 }
42 
SerializeNotification(MessageParcel & data,const Notification & notification)43 void SerializeNotification(MessageParcel &data, const Notification &notification)
44 {
45     if (notification.title != std::nullopt) {
46         data.WriteBool(true);
47         data.WriteString(*notification.title);
48     } else {
49         data.WriteBool(false);
50     }
51     if (notification.text != std::nullopt) {
52         data.WriteBool(true);
53         data.WriteString(*notification.text);
54     } else {
55         data.WriteBool(false);
56     }
57 }
58 
Create(const Config & config,std::string & tid)59 int32_t RequestServiceProxy::Create(const Config &config, std::string &tid)
60 {
61     MessageParcel data, reply;
62     MessageOption option;
63     data.WriteInterfaceToken(GetDescriptor());
64     data.WriteUint32(static_cast<uint32_t>(config.action));
65     data.WriteUint32(static_cast<uint32_t>(config.version));
66     data.WriteUint32(static_cast<uint32_t>(config.mode));
67     data.WriteUint32(static_cast<uint32_t>(config.bundleType));
68     data.WriteBool(config.overwrite);
69     data.WriteUint32(static_cast<uint32_t>(config.network));
70     data.WriteBool(config.metered);
71     data.WriteBool(config.roaming);
72     data.WriteBool(config.retry);
73     data.WriteBool(config.redirect);
74     data.WriteBool(config.background);
75     data.WriteBool(config.multipart);
76     data.WriteUint32(config.index);
77     data.WriteInt64(config.begins);
78     data.WriteInt64(config.ends);
79     data.WriteBool(config.gauge);
80     data.WriteBool(config.precise);
81     data.WriteUint32(config.priority);
82     data.WriteString(config.url);
83     data.WriteString(config.title);
84     data.WriteString(config.method);
85     data.WriteString(config.token);
86     data.WriteString(config.description);
87     data.WriteString(config.data);
88     data.WriteString(config.proxy);
89     data.WriteString(config.certificatePins);
90     GetVectorData(config, data);
91     SerializeNotification(data, config.notification);
92 
93     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_REQUEST), data, reply, option);
94     if (ret != ERR_NONE) {
95         REQUEST_HILOGE("End send create request, failed: %{public}d", ret);
96         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, config.bundleName, "", std::to_string(ret));
97         return E_SERVICE_ERROR;
98     }
99     int32_t errCode = reply.ReadInt32();
100     if (errCode != E_OK && errCode != E_CHANNEL_NOT_OPEN) {
101         REQUEST_HILOGE("End send create request, failed: %{public}d", errCode);
102         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_01, config.bundleName, "", std::to_string(errCode));
103         return errCode;
104     }
105     tid = std::to_string(reply.ReadInt32());
106     return errCode;
107 }
108 
GetVectorData(const Config & config,MessageParcel & data)109 void RequestServiceProxy::GetVectorData(const Config &config, MessageParcel &data)
110 {
111     data.WriteUint32(config.certsPath.size());
112     for (const auto &cert : config.certsPath) {
113         data.WriteString(cert);
114     }
115 
116     data.WriteUint32(config.forms.size());
117     for (const auto &form : config.forms) {
118         data.WriteString(form.name);
119         data.WriteString(form.value);
120     }
121     data.WriteUint32(config.files.size());
122     for (const auto &file : config.files) {
123         data.WriteString(file.name);
124         data.WriteString(file.uri);
125         data.WriteString(file.filename);
126         data.WriteString(file.type);
127         data.WriteBool(file.isUserFile);
128         if (file.isUserFile) {
129             data.WriteFileDescriptor(file.fd);
130         }
131     }
132 
133     // Response Body files.
134     data.WriteUint32(config.bodyFileNames.size());
135     for (const auto &name : config.bodyFileNames) {
136         data.WriteString(name);
137     }
138 
139     data.WriteUint32(config.headers.size());
140     for (const auto &header : config.headers) {
141         data.WriteString(header.first);
142         data.WriteString(header.second);
143     }
144     data.WriteUint32(config.extras.size());
145     for (const auto &extra : config.extras) {
146         data.WriteString(extra.first);
147         data.WriteString(extra.second);
148     }
149 }
150 
GetTask(const std::string & tid,const std::string & token,Config & config)151 int32_t RequestServiceProxy::GetTask(const std::string &tid, const std::string &token, Config &config)
152 {
153     REQUEST_HILOGD("Request GetTask, tid: %{public}s", tid.c_str());
154     MessageParcel data, reply;
155     MessageOption option;
156     data.WriteInterfaceToken(GetDescriptor());
157     data.WriteString(tid);
158     data.WriteString(token);
159     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_GETTASK), data, reply, option);
160     if (ret != ERR_NONE) {
161         REQUEST_HILOGE("End Request GetTask, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
162         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, config.bundleName, "", std::to_string(ret));
163         return E_SERVICE_ERROR;
164     }
165     int32_t errCode = reply.ReadInt32();
166     if (errCode != E_OK && errCode != E_CHANNEL_NOT_OPEN) {
167         REQUEST_HILOGE("End Request GetTask, failed: %{public}d", errCode);
168         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_01, config.bundleName, "", std::to_string(errCode));
169         return errCode;
170     }
171     ParcelHelper::UnMarshalConfig(reply, config);
172     REQUEST_HILOGD("End Request GetTask ok, tid: %{public}s", tid.c_str());
173     return errCode;
174 }
175 
Start(const std::string & tid)176 int32_t RequestServiceProxy::Start(const std::string &tid)
177 {
178     REQUEST_HILOGD("Request Start, tid: %{public}s", tid.c_str());
179     MessageParcel data, reply;
180     MessageOption option;
181     data.WriteInterfaceToken(GetDescriptor());
182     data.WriteString(tid);
183 
184     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_START), data, reply, option);
185     if (ret != ERR_NONE) {
186         REQUEST_HILOGE("End Request Start, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
187         return E_SERVICE_ERROR;
188     }
189     REQUEST_HILOGD("End Request Start ok, tid: %{public}s", tid.c_str());
190     return reply.ReadInt32();
191 }
192 
Stop(const std::string & tid)193 int32_t RequestServiceProxy::Stop(const std::string &tid)
194 {
195     REQUEST_HILOGD("Request Stop, tid: %{public}s", tid.c_str());
196     MessageParcel data, reply;
197     MessageOption option;
198     data.WriteInterfaceToken(GetDescriptor());
199     data.WriteString(tid);
200     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_STOP), data, reply, option);
201     if (ret != ERR_NONE) {
202         REQUEST_HILOGE("End Request Stop, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
203         return E_SERVICE_ERROR;
204     }
205     REQUEST_HILOGD("End Request Stop ok, tid: %{public}s", tid.c_str());
206     return reply.ReadInt32();
207 }
208 
Query(const std::string & tid,TaskInfo & info)209 int32_t RequestServiceProxy::Query(const std::string &tid, TaskInfo &info)
210 {
211     REQUEST_HILOGD("Request Query, tid: %{public}s", tid.c_str());
212     MessageParcel data, reply;
213     MessageOption option;
214     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
215     data.WriteString(tid);
216     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_QUERY), data, reply, option);
217     if (ret != ERR_NONE) {
218         REQUEST_HILOGE("End Request Query, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
219         return E_SERVICE_ERROR;
220     }
221     int32_t errCode = reply.ReadInt32();
222     if (errCode != E_OK) {
223         REQUEST_HILOGE("End Request Query, tid: %{public}s, failed: %{public}d", tid.c_str(), errCode);
224         return errCode;
225     }
226     ParcelHelper::UnMarshal(reply, info);
227     REQUEST_HILOGD("End Request Query ok, tid: %{public}s", tid.c_str());
228     return E_OK;
229 }
230 
Touch(const std::string & tid,const std::string & token,TaskInfo & info)231 int32_t RequestServiceProxy::Touch(const std::string &tid, const std::string &token, TaskInfo &info)
232 {
233     REQUEST_HILOGD("Request Touch, tid: %{public}s", tid.c_str());
234     MessageParcel data, reply;
235     MessageOption option;
236     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
237     data.WriteString(tid);
238     data.WriteString(token);
239     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_TOUCH), data, reply, option);
240     if (ret != ERR_NONE) {
241         REQUEST_HILOGE("End Request Touch, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
242         return E_SERVICE_ERROR;
243     }
244     int32_t errCode = reply.ReadInt32();
245     if (errCode != E_OK) {
246         REQUEST_HILOGE("End Request Touch, tid: %{public}s, failed: %{public}d", tid.c_str(), errCode);
247         return errCode;
248     }
249     ParcelHelper::UnMarshal(reply, info);
250     REQUEST_HILOGD("End Request Touch ok, tid: %{public}s", tid.c_str());
251     return E_OK;
252 }
253 
Search(const Filter & filter,std::vector<std::string> & tids)254 int32_t RequestServiceProxy::Search(const Filter &filter, std::vector<std::string> &tids)
255 {
256     REQUEST_HILOGD("Request Search");
257     MessageParcel data, reply;
258     MessageOption option;
259     data.WriteInterfaceToken(GetDescriptor());
260     data.WriteString(filter.bundle);
261     data.WriteInt64(filter.before);
262     data.WriteInt64(filter.after);
263     data.WriteUint32(static_cast<uint32_t>(filter.state));
264     data.WriteUint32(static_cast<uint32_t>(filter.action));
265     data.WriteUint32(static_cast<uint32_t>(filter.mode));
266     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_SEARCH), data, reply, option);
267     if (ret != ERR_NONE) {
268         REQUEST_HILOGE("End Request Search, failed: %{public}d", ret);
269         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
270         return E_SERVICE_ERROR;
271     }
272     uint32_t size = reply.ReadUint32();
273     for (uint32_t i = 0; i < size; i++) {
274         tids.push_back(reply.ReadString());
275     }
276     REQUEST_HILOGD("End Request Search ok");
277     return E_OK;
278 }
279 
Show(const std::string & tid,TaskInfo & info)280 int32_t RequestServiceProxy::Show(const std::string &tid, TaskInfo &info)
281 {
282     REQUEST_HILOGD("Request Show, tid: %{public}s", tid.c_str());
283     MessageParcel data, reply;
284     MessageOption option;
285     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
286     data.WriteString(tid);
287     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_SHOW), data, reply, option);
288     if (ret != ERR_NONE) {
289         REQUEST_HILOGE("End Request Show, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
290         return E_SERVICE_ERROR;
291     }
292     int32_t errCode = reply.ReadInt32();
293     if (errCode != E_OK) {
294         REQUEST_HILOGE("End Request Show, tid: %{public}s, failed: %{public}d", tid.c_str(), errCode);
295         return errCode;
296     }
297     ParcelHelper::UnMarshal(reply, info);
298     REQUEST_HILOGD("End Request Show ok, tid: %{public}s", tid.c_str());
299     return E_OK;
300 }
301 
Pause(const std::string & tid,Version version)302 int32_t RequestServiceProxy::Pause(const std::string &tid, Version version)
303 {
304     REQUEST_HILOGD("Request Pause, tid: %{public}s", tid.c_str());
305     MessageParcel data, reply;
306     MessageOption option;
307     data.WriteInterfaceToken(GetDescriptor());
308     data.WriteUint32(static_cast<uint32_t>(version));
309     data.WriteString(tid);
310     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_PAUSE), data, reply, option);
311     if (ret != ERR_NONE) {
312         REQUEST_HILOGE("End Request Pause, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
313         return E_SERVICE_ERROR;
314     }
315     REQUEST_HILOGD("End Request Pause ok, tid: %{public}s", tid.c_str());
316     return reply.ReadInt32();
317 }
318 
QueryMimeType(const std::string & tid,std::string & mimeType)319 int32_t RequestServiceProxy::QueryMimeType(const std::string &tid, std::string &mimeType)
320 {
321     REQUEST_HILOGD("Request QueryMimeType, tid: %{public}s", tid.c_str());
322     MessageParcel data, reply;
323     MessageOption option;
324     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
325     data.WriteString(tid);
326     int32_t ret =
327         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_QUERYMIMETYPE), data, reply, option);
328     if (ret != ERR_NONE) {
329         REQUEST_HILOGE("End Request QueryMimeType, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
330         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
331         return E_SERVICE_ERROR;
332     }
333     int32_t errCode = reply.ReadInt32();
334     if (errCode != E_OK) {
335         REQUEST_HILOGE("End Request QueryMimeType, tid: %{public}s, failed: %{public}d", tid.c_str(), errCode);
336         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_01, std::to_string(errCode));
337         return errCode;
338     }
339     mimeType = reply.ReadString();
340     REQUEST_HILOGD("End Request QueryMimeType ok, tid: %{public}s", tid.c_str());
341     return E_OK;
342 }
343 
Remove(const std::string & tid,Version version)344 int32_t RequestServiceProxy::Remove(const std::string &tid, Version version)
345 {
346     REQUEST_HILOGD("Request Remove, tid: %{public}s", tid.c_str());
347     MessageParcel data, reply;
348     MessageOption option;
349     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
350     data.WriteUint32(static_cast<uint32_t>(version));
351     data.WriteString(tid);
352     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_REMOVE), data, reply, option);
353     if (ret != ERR_NONE) {
354         REQUEST_HILOGE("End Request Remove, tid: %{public}s failed: %{public}d", tid.c_str(), ret);
355         return E_SERVICE_ERROR;
356     }
357 
358     // API9 or lower will not return E_TASK_NOT_FOUND.
359     int32_t result = reply.ReadInt32();
360     if (version == Version::API9) {
361         REQUEST_HILOGD("End Request Remove ok, tid: %{public}s", tid.c_str());
362         result = E_OK;
363     }
364     REQUEST_HILOGD("End Request Remove ok, tid: %{public}s, result: %{public}d", tid.c_str(), result);
365     return result;
366 }
367 
Resume(const std::string & tid)368 int32_t RequestServiceProxy::Resume(const std::string &tid)
369 {
370     REQUEST_HILOGD("Request Resume, tid: %{public}s", tid.c_str());
371     MessageParcel data, reply;
372     MessageOption option;
373     data.WriteInterfaceToken(RequestServiceProxy::GetDescriptor());
374     data.WriteString(tid);
375     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_RESUME), data, reply, option);
376     if (ret != ERR_NONE) {
377         REQUEST_HILOGE("End Request Resume, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
378         return E_SERVICE_ERROR;
379     }
380     REQUEST_HILOGD("End Request Resume ok, tid: %{public}s", tid.c_str());
381     return reply.ReadInt32();
382 }
383 
OpenChannel(int32_t & sockFd)384 int32_t RequestServiceProxy::OpenChannel(int32_t &sockFd)
385 {
386     REQUEST_HILOGD("Request OpenChannel");
387     MessageParcel data, reply;
388     MessageOption option;
389     data.WriteInterfaceToken(GetDescriptor());
390     int32_t ret =
391         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_OPENCHANNEL), data, reply, option);
392     if (ret != ERR_NONE) {
393         REQUEST_HILOGE("End Request OpenChannel, failed: %{public}d", ret);
394         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
395         return E_SERVICE_ERROR;
396     }
397     int32_t errCode = reply.ReadInt32();
398     if (errCode != E_OK) {
399         REQUEST_HILOGE("End Request OpenChannel, failed: %{public}d", errCode);
400         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_01, std::to_string(errCode));
401         return errCode;
402     }
403     sockFd = reply.ReadFileDescriptor();
404     REQUEST_HILOGD("End Request OpenChannel ok, fd: %{public}d", sockFd);
405     return E_OK;
406 }
407 
Subscribe(const std::string & tid)408 int32_t RequestServiceProxy::Subscribe(const std::string &tid)
409 {
410     REQUEST_HILOGD("Request Subscribe, tid: %{public}s", tid.c_str());
411     MessageParcel data, reply;
412     MessageOption option;
413     data.WriteInterfaceToken(GetDescriptor());
414     data.WriteString(tid);
415     int32_t ret =
416         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_SUBSCRIBE), data, reply, option);
417     if (ret != ERR_NONE) {
418         REQUEST_HILOGE("End Request Subscribe, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
419         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
420         return E_SERVICE_ERROR;
421     }
422     REQUEST_HILOGD("End Request Subscribe ok, tid: %{public}s", tid.c_str());
423     int32_t errCode = reply.ReadInt32();
424     return errCode;
425 }
426 
Unsubscribe(const std::string & tid)427 int32_t RequestServiceProxy::Unsubscribe(const std::string &tid)
428 {
429     REQUEST_HILOGD("Request Unsubscribe, tid: %{public}s", tid.c_str());
430     MessageParcel data, reply;
431     MessageOption option;
432     data.WriteInterfaceToken(GetDescriptor());
433     data.WriteString(tid);
434     int32_t ret =
435         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_UNSUBSCRIBE), data, reply, option);
436     if (ret != ERR_NONE) {
437         REQUEST_HILOGE("End Request Unsubscribe, tid: %{public}s, failed: %{public}d", tid.c_str(), ret);
438         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
439         return E_SERVICE_ERROR;
440     }
441     REQUEST_HILOGD("End Request Unsubscribe ok, tid: %{public}s", tid.c_str());
442     return E_OK;
443 }
444 
SubRunCount(const sptr<NotifyInterface> & listener)445 int32_t RequestServiceProxy::SubRunCount(const sptr<NotifyInterface> &listener)
446 {
447     REQUEST_HILOGD("Request SubRunCount");
448     FwkRunningTaskCountManager::GetInstance()->SetSaStatus(true);
449     MessageParcel data, reply;
450     MessageOption option;
451     data.WriteInterfaceToken(GetDescriptor());
452     data.WriteRemoteObject(listener->AsObject());
453     int32_t ret =
454         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_SUB_RUNCOUNT), data, reply, option);
455     if (ret != ERR_NONE) {
456         REQUEST_HILOGE("End Request SubRunCount, failed: %{public}d", ret);
457         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
458         return ret;
459     }
460     int32_t errCode = reply.ReadInt32();
461     if (errCode != E_OK) {
462         REQUEST_HILOGE("End Request SubRunCount, failed: %{public}d", errCode);
463         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_01, std::to_string(errCode));
464         return errCode;
465     }
466     REQUEST_HILOGD("End Request SubRunCount ok");
467     return E_OK;
468 }
469 
UnsubRunCount()470 int32_t RequestServiceProxy::UnsubRunCount()
471 {
472     REQUEST_HILOGD("Request UnubRunCount");
473     MessageParcel data, reply;
474     MessageOption option;
475     data.WriteInterfaceToken(GetDescriptor());
476     int32_t ret =
477         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_UNSUB_RUNCOUNT), data, reply, option);
478     if (ret != ERR_NONE) {
479         REQUEST_HILOGE("End Request UnubRunCount, failed: %{public}d", ret);
480         SysEventLog::SendSysEventLog(FAULT_EVENT, IPC_FAULT_00, std::to_string(ret));
481         return E_SERVICE_ERROR;
482     }
483     REQUEST_HILOGD("End Request UnubRunCount ok");
484     return E_OK;
485 }
486 
CreateGroup(std::string & gid,const bool gauge,std::optional<std::string> title,std::optional<std::string> text)487 int32_t RequestServiceProxy::CreateGroup(
488     std::string &gid, const bool gauge, std::optional<std::string> title, std::optional<std::string> text)
489 {
490     MessageParcel data;
491     MessageParcel reply;
492     MessageOption option;
493     data.WriteInterfaceToken(GetDescriptor());
494     data.WriteBool(gauge);
495     if (title != std::nullopt) {
496         data.WriteBool(true);
497         data.WriteString(*title);
498     } else {
499         data.WriteBool(false);
500     }
501     if (text != std::nullopt) {
502         data.WriteBool(true);
503         data.WriteString(*text);
504     } else {
505         data.WriteBool(false);
506     }
507     int32_t ret =
508         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_CREATE_GROUP), data, reply, option);
509     if (ret != ERR_NONE) {
510         REQUEST_HILOGE("End Request AttachGroup, failed: %{public}d", ret);
511         return E_SERVICE_ERROR;
512     }
513     gid = reply.ReadString();
514     return E_OK;
515 }
516 
AttachGroup(const std::string & gid,const std::vector<std::string> & tids)517 int32_t RequestServiceProxy::AttachGroup(const std::string &gid, const std::vector<std::string> &tids)
518 {
519     MessageParcel data;
520     MessageParcel reply;
521     MessageOption option;
522     data.WriteInterfaceToken(GetDescriptor());
523     data.WriteString(gid);
524     data.WriteStringVector(tids);
525     int32_t ret =
526         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_ATTACH_GROUP), data, reply, option);
527     if (ret != ERR_NONE) {
528         REQUEST_HILOGE("End Request AttachGroup, failed: %{public}d", ret);
529         return E_SERVICE_ERROR;
530     }
531     int code = reply.ReadInt32();
532     if (code != E_OK) {
533         REQUEST_HILOGE("End Request AttachGroup, failed: %{public}d", code);
534     }
535     return code;
536 }
537 
DeleteGroup(const std::string & gid)538 int32_t RequestServiceProxy::DeleteGroup(const std::string &gid)
539 {
540     MessageParcel data;
541     MessageParcel reply;
542     MessageOption option;
543     data.WriteInterfaceToken(GetDescriptor());
544     data.WriteString(gid);
545     int32_t ret =
546         Remote()->SendRequest(static_cast<uint32_t>(RequestInterfaceCode::CMD_DELETE_GROUP), data, reply, option);
547     if (ret != ERR_NONE) {
548         REQUEST_HILOGE("End Request AttachGroup, failed: %{public}d", ret);
549         return E_SERVICE_ERROR;
550     }
551     int code = reply.ReadInt32();
552     if (code != E_OK) {
553         REQUEST_HILOGE("End Request AttachGroup, failed: %{public}d", code);
554     }
555     return code;
556 }
557 
558 } // namespace OHOS::Request
559