1 /*
2  * Copyright (c) 2022-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 #include "datashare_proxy.h"
17 
18 #include <string_ex.h>
19 
20 #include "data_ability_observer_interface.h"
21 #include "datashare_itypes_utils.h"
22 #include "datashare_log.h"
23 #include "datashare_result_set.h"
24 #include "ipc_types.h"
25 #include "ishared_result_set.h"
26 #include "pac_map.h"
27 
28 using namespace OHOS::DistributedShare::DataShare;
29 
30 namespace OHOS {
31 namespace DataShare {
32 constexpr int32_t PERMISSION_ERR = 1;
33 constexpr int PERMISSION_ERR_CODE = -2;
GetFileTypes(const Uri & uri,const std::string & mimeTypeFilter)34 std::vector<std::string> DataShareProxy::GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter)
35 {
36     std::vector<std::string> types;
37 
38     MessageParcel data;
39     MessageParcel reply;
40     MessageOption option;
41 
42     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
43         LOG_ERROR("WriteInterfaceToken failed");
44         return types;
45     }
46 
47     if (!data.WriteParcelable(&uri)) {
48         LOG_ERROR("fail to WriteParcelable uri");
49         return types;
50     }
51 
52     if (!data.WriteString(mimeTypeFilter)) {
53         LOG_ERROR("fail to WriteString mimeTypeFilter");
54         return types;
55     }
56 
57     int32_t err = Remote()->SendRequest(
58         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_GET_FILE_TYPES), data, reply, option);
59     if (err != E_OK) {
60         LOG_ERROR("GetFileTypes fail to SendRequest. err: %{public}d", err);
61     }
62 
63     if (!reply.ReadStringVector(&types)) {
64         LOG_ERROR("fail to ReadStringVector types");
65     }
66 
67     return types;
68 }
69 
OpenFile(const Uri & uri,const std::string & mode)70 int DataShareProxy::OpenFile(const Uri &uri, const std::string &mode)
71 {
72     int fd = -1;
73     MessageParcel data;
74     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
75         LOG_ERROR("WriteInterfaceToken failed");
76         return fd;
77     }
78 
79     if (!data.WriteParcelable(&uri)) {
80         LOG_ERROR("fail to WriteParcelable uri");
81         return fd;
82     }
83 
84     if (!data.WriteString(mode)) {
85         LOG_ERROR("fail to WriteString mode");
86         return fd;
87     }
88 
89     MessageParcel reply;
90     MessageOption option;
91     int32_t err = Remote()->SendRequest(
92         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_OPEN_FILE), data, reply, option);
93     if (err != E_OK) {
94         LOG_ERROR("OpenFile fail to SendRequest. err: %{public}d", err);
95         return fd;
96     }
97 
98     fd = reply.ReadFileDescriptor();
99     if (fd == -1) {
100         LOG_ERROR("fail to ReadFileDescriptor fd");
101         return fd;
102     }
103 
104     return fd;
105 }
106 
OpenRawFile(const Uri & uri,const std::string & mode)107 int DataShareProxy::OpenRawFile(const Uri &uri, const std::string &mode)
108 {
109     int fd = -1;
110     MessageParcel data;
111     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
112         LOG_ERROR("WriteInterfaceToken failed");
113         return fd;
114     }
115 
116     if (!data.WriteParcelable(&uri)) {
117         LOG_ERROR("fail to WriteParcelable uri");
118         return fd;
119     }
120 
121     if (!data.WriteString(mode)) {
122         LOG_ERROR("fail to WriteString mode");
123         return fd;
124     }
125 
126     MessageParcel reply;
127     MessageOption option;
128     int32_t err = Remote()->SendRequest(
129         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_OPEN_RAW_FILE), data, reply, option);
130     if (err != E_OK) {
131         LOG_ERROR("OpenRawFile fail to SendRequest. err: %{public}d", err);
132         return fd;
133     }
134 
135     if (!reply.ReadInt32(fd)) {
136         LOG_ERROR("fail to ReadInt32 fd");
137         return fd;
138     }
139 
140     return fd;
141 }
142 
Insert(const Uri & uri,const DataShareValuesBucket & value)143 int DataShareProxy::Insert(const Uri &uri, const DataShareValuesBucket &value)
144 {
145     int index = -1;
146     MessageParcel data;
147     data.SetMaxCapacity(MTU_SIZE);
148     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
149         LOG_ERROR("WriteInterfaceToken failed");
150         return index;
151     }
152     if (!ITypesUtil::Marshal(data, uri, value)) {
153         LOG_ERROR("fail to Marshal value");
154         return index;
155     }
156     MessageParcel reply;
157     MessageOption option;
158     int32_t err = Remote()->SendRequest(
159         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT), data, reply, option);
160     if (err != E_OK) {
161         LOG_ERROR("Insert fail to SendRequest. err: %{public}d", err);
162         return err == PERMISSION_ERR ? PERMISSION_ERR_CODE : index;
163     }
164     if (!ITypesUtil::Unmarshal(reply, index)) {
165         LOG_ERROR("fail to Unmarshal index");
166         return index;
167     }
168 
169     return index;
170 }
171 
InsertExt(const Uri & uri,const DataShareValuesBucket & value,std::string & result)172 int DataShareProxy::InsertExt(const Uri &uri, const DataShareValuesBucket &value, std::string &result)
173 {
174     int index = -1;
175     MessageParcel data;
176     data.SetMaxCapacity(MTU_SIZE);
177     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
178         LOG_ERROR("WriteInterfaceToken failed");
179         return index;
180     }
181     if (!ITypesUtil::Marshal(data, uri, value)) {
182         LOG_ERROR("fail to Marshal value");
183         return index;
184     }
185     MessageParcel reply;
186     MessageOption option;
187     int32_t err = Remote()->SendRequest(
188         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT_EXT), data, reply, option);
189     if (err != E_OK) {
190         LOG_ERROR("Insert fail to SendRequest. err: %{public}d", err);
191         return index;
192     }
193     if (!ITypesUtil::Unmarshal(reply, index, result)) {
194         LOG_ERROR("fail to Unmarshal index");
195         return index;
196     }
197     return index;
198 }
199 
Update(const Uri & uri,const DataSharePredicates & predicates,const DataShareValuesBucket & value)200 int DataShareProxy::Update(const Uri &uri, const DataSharePredicates &predicates, const DataShareValuesBucket &value)
201 {
202     int index = -1;
203     MessageParcel data;
204     data.SetMaxCapacity(MTU_SIZE);
205     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
206         LOG_ERROR("WriteInterfaceToken failed");
207         return index;
208     }
209     if (!ITypesUtil::Marshal(data, uri, predicates, value)) {
210         LOG_ERROR("fail to Marshal value");
211         return index;
212     }
213     MessageParcel reply;
214     MessageOption option;
215     int32_t err = Remote()->SendRequest(
216         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UPDATE), data, reply, option);
217     if (err != E_OK) {
218         LOG_ERROR("Update fail to SendRequest. err: %{public}d", err);
219         return err == PERMISSION_ERR ? PERMISSION_ERR_CODE : index;
220     }
221     if (!ITypesUtil::Unmarshal(reply, index)) {
222         LOG_ERROR("fail to Unmarshal index");
223         return index;
224     }
225     return index;
226 }
227 
BatchUpdate(const UpdateOperations & operations,std::vector<BatchUpdateResult> & results)228 int DataShareProxy::BatchUpdate(const UpdateOperations &operations, std::vector<BatchUpdateResult> &results)
229 {
230     int ret = -1;
231     MessageParcel data;
232     data.SetMaxCapacity(MTU_SIZE);
233     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
234         LOG_ERROR("WriteInterfaceToken failed");
235         return ret;
236     }
237     if (!CheckSize(operations)) {
238         return ret;
239     }
240     if (!ITypesUtil::Marshal(data, operations)) {
241         LOG_ERROR("fail to Marshalling");
242         return ret;
243     }
244     MessageParcel reply;
245     MessageOption option;
246     int32_t err = Remote()->SendRequest(
247         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_BATCH_UPDATE), data, reply, option);
248     if (err != E_OK) {
249         LOG_ERROR("fail to SendRequest. err: %{public}d", err);
250         return err;
251     }
252     if (!ITypesUtil::Unmarshal(reply, results)) {
253         LOG_ERROR("fail to Unmarshal result");
254         return ret;
255     }
256     return 0;
257 }
258 
Delete(const Uri & uri,const DataSharePredicates & predicates)259 int DataShareProxy::Delete(const Uri &uri, const DataSharePredicates &predicates)
260 {
261     int index = -1;
262     MessageParcel data;
263     data.SetMaxCapacity(MTU_SIZE);
264     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
265         LOG_ERROR("WriteInterfaceToken failed");
266         return index;
267     }
268     if (!ITypesUtil::Marshal(data, uri, predicates)) {
269         LOG_ERROR("fail to Marshalling predicates");
270         return index;
271     }
272 
273     MessageParcel reply;
274     MessageOption option;
275     int32_t err = Remote()->SendRequest(
276         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DELETE), data, reply, option);
277     if (err != E_OK) {
278         LOG_ERROR("Delete fail to SendRequest. err: %{public}d", err);
279         return err == PERMISSION_ERR ? PERMISSION_ERR_CODE : index;
280     }
281     if (!ITypesUtil::Unmarshal(reply, index)) {
282         LOG_ERROR("fail to Unmarshal index");
283         return index;
284     }
285     return index;
286 }
287 
InsertEx(const Uri & uri,const DataShareValuesBucket & value)288 std::pair<int32_t, int32_t> DataShareProxy::InsertEx(const Uri &uri, const DataShareValuesBucket &value)
289 {
290     MessageParcel data;
291     data.SetMaxCapacity(MTU_SIZE);
292     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
293         LOG_ERROR("WriteInterfaceToken failed");
294         return std::make_pair(E_WRITE_TO_PARCE_ERROR, 0);
295     }
296     if (!ITypesUtil::Marshal(data, uri, value)) {
297         LOG_ERROR("fail to Marshal value");
298         return std::make_pair(E_MARSHAL_ERROR, 0);
299     }
300 
301     int32_t errCode = -1;
302     int32_t result = -1;
303     MessageParcel reply;
304     MessageOption option;
305     int32_t err = Remote()->SendRequest(
306         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT_EX), data, reply, option);
307     if (err != E_OK) {
308         LOG_ERROR("InsertEx fail to SendRequest. err: %{public}d", err);
309         return std::make_pair((err == PERMISSION_ERR ? PERMISSION_ERR_CODE : errCode), 0);
310     }
311 
312     if (!ITypesUtil::Unmarshal(reply, errCode, result)) {
313         LOG_ERROR("fail to Unmarshal");
314         return std::make_pair(E_UNMARSHAL_ERROR, 0);
315     }
316     return std::make_pair(errCode, result);
317 }
318 
UpdateEx(const Uri & uri,const DataSharePredicates & predicates,const DataShareValuesBucket & value)319 std::pair<int32_t, int32_t> DataShareProxy::UpdateEx(const Uri &uri, const DataSharePredicates &predicates,
320     const DataShareValuesBucket &value)
321 {
322     MessageParcel data;
323     data.SetMaxCapacity(MTU_SIZE);
324     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
325         LOG_ERROR("WriteInterfaceToken failed");
326         return std::make_pair(E_WRITE_TO_PARCE_ERROR, 0);
327     }
328     if (!ITypesUtil::Marshal(data, uri, predicates, value)) {
329         LOG_ERROR("fail to Marshal value");
330         return std::make_pair(E_MARSHAL_ERROR, 0);
331     }
332 
333     int32_t errCode = -1;
334     int32_t result = -1;
335     MessageParcel reply;
336     MessageOption option;
337     int32_t err = Remote()->SendRequest(
338         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UPDATE_EX), data, reply, option);
339     if (err != E_OK) {
340         LOG_ERROR("UpdateEx fail to SendRequest. err: %{public}d", err);
341         return std::make_pair((err == PERMISSION_ERR ? PERMISSION_ERR_CODE : errCode), 0);
342     }
343 
344     if (!ITypesUtil::Unmarshal(reply, errCode, result)) {
345         LOG_ERROR("fail to Unmarshal");
346         return std::make_pair(E_UNMARSHAL_ERROR, 0);
347     }
348     return std::make_pair(errCode, result);
349 }
350 
DeleteEx(const Uri & uri,const DataSharePredicates & predicates)351 std::pair<int32_t, int32_t> DataShareProxy::DeleteEx(const Uri &uri, const DataSharePredicates &predicates)
352 {
353     MessageParcel data;
354     data.SetMaxCapacity(MTU_SIZE);
355     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
356         LOG_ERROR("WriteInterfaceToken failed");
357         return std::make_pair(E_WRITE_TO_PARCE_ERROR, 0);
358     }
359     if (!ITypesUtil::Marshal(data, uri, predicates)) {
360         LOG_ERROR("fail to Marshalling predicates");
361         return std::make_pair(E_MARSHAL_ERROR, 0);
362     }
363 
364     int32_t errCode = -1;
365     int32_t result = -1;
366     MessageParcel reply;
367     MessageOption option;
368     int32_t err = Remote()->SendRequest(
369         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DELETE_EX), data, reply, option);
370     if (err != E_OK) {
371         LOG_ERROR("DeleteEx fail to SendRequest. err: %{public}d", err);
372         return std::make_pair((err == PERMISSION_ERR ? PERMISSION_ERR_CODE : errCode), 0);
373     }
374 
375     if (!ITypesUtil::Unmarshal(reply, errCode, result)) {
376         LOG_ERROR("fail to Unmarshal");
377         return std::make_pair(E_UNMARSHAL_ERROR, 0);
378     }
379     return std::make_pair(errCode, result);
380 }
381 
Query(const Uri & uri,const DataSharePredicates & predicates,std::vector<std::string> & columns,DatashareBusinessError & businessError)382 std::shared_ptr<DataShareResultSet> DataShareProxy::Query(const Uri &uri, const DataSharePredicates &predicates,
383     std::vector<std::string> &columns, DatashareBusinessError &businessError)
384 {
385     MessageParcel data;
386     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
387         LOG_ERROR("WriteInterfaceToken failed");
388         return nullptr;
389     }
390     if (!ITypesUtil::Marshal(data, uri, predicates, columns)) {
391         LOG_ERROR("fail to Marshalling");
392         return nullptr;
393     }
394     MessageParcel reply;
395     MessageOption option;
396     int32_t err = Remote()->SendRequest(
397         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_QUERY), data, reply, option);
398     auto result = ISharedResultSet::ReadFromParcel(reply);
399     businessError.SetCode(reply.ReadInt32());
400     businessError.SetMessage(reply.ReadString());
401     if (err != E_OK) {
402         LOG_ERROR("Query fail to SendRequest. err: %{public}d", err);
403         return nullptr;
404     }
405     return result;
406 }
407 
GetType(const Uri & uri)408 std::string DataShareProxy::GetType(const Uri &uri)
409 {
410     std::string type;
411     MessageParcel data;
412     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
413         LOG_ERROR("WriteInterfaceToken failed");
414         return type;
415     }
416 
417     if (!ITypesUtil::Marshal(data, uri)) {
418         LOG_ERROR("fail to Marshal value");
419         return type;
420     }
421 
422     MessageParcel reply;
423     MessageOption option;
424     int32_t err = Remote()->SendRequest(
425         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_GET_TYPE), data, reply, option);
426     if (err != E_OK) {
427         LOG_ERROR("GetFileTypes fail to SendRequest. err: %{public}d", err);
428         return type;
429     }
430     if (!ITypesUtil::Unmarshal(reply, type)) {
431         LOG_ERROR("fail to Unmarshal index");
432         return type;
433     }
434     if (type.empty()) {
435         LOG_ERROR("fail to ReadString type");
436         return type;
437     }
438 
439     return type;
440 }
441 
BatchInsert(const Uri & uri,const std::vector<DataShareValuesBucket> & values)442 int DataShareProxy::BatchInsert(const Uri &uri, const std::vector<DataShareValuesBucket> &values)
443 {
444     int ret = -1;
445     MessageParcel data;
446     data.SetMaxCapacity(MTU_SIZE);
447     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
448         LOG_ERROR("WriteInterfaceToken failed");
449         return ret;
450     }
451     if (!ITypesUtil::Marshal(data, uri, values)) {
452         LOG_ERROR("fail to Marshalling");
453         return ret;
454     }
455 
456     MessageParcel reply;
457     MessageOption option;
458     int32_t err = Remote()->SendRequest(
459         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_BATCH_INSERT), data, reply, option);
460     if (err != E_OK) {
461         LOG_ERROR("fail to SendRequest. err: %{public}d", err);
462         return err == PERMISSION_ERR ? PERMISSION_ERR_CODE : ret;
463     }
464     if (!ITypesUtil::Unmarshal(reply, ret)) {
465         LOG_ERROR("fail to Unmarshal index");
466         return ret;
467     }
468     return ret;
469 }
470 
ExecuteBatch(const std::vector<OperationStatement> & statements,ExecResultSet & result)471 int DataShareProxy::ExecuteBatch(const std::vector<OperationStatement> &statements, ExecResultSet &result)
472 {
473     MessageParcel data;
474     data.SetMaxCapacity(MTU_SIZE);
475     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
476         LOG_ERROR("WriteInterfaceToken failed");
477         return -1;
478     }
479     if (!ITypesUtil::Marshal(data, statements)) {
480         LOG_ERROR("fail to Marshal");
481         return -1;
482     }
483 
484     MessageParcel reply;
485     MessageOption option;
486     int32_t err = Remote()->SendRequest(
487         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_EXECUTE_BATCH), data, reply, option);
488     if (err != E_OK) {
489         LOG_ERROR("fail to SendRequest. err: %{public}d", err);
490         return -1;
491     }
492     if (!ITypesUtil::Unmarshal(reply, result)) {
493         LOG_ERROR("fail to Unmarshal result");
494         return -1;
495     }
496     return 0;
497 }
498 
RegisterObserver(const Uri & uri,const sptr<AAFwk::IDataAbilityObserver> & dataObserver)499 bool DataShareProxy::RegisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver)
500 {
501     MessageParcel data;
502     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
503         LOG_ERROR("WriteInterfaceToken failed");
504         return false;
505     }
506 
507     if (!ITypesUtil::Marshal(data, uri, dataObserver->AsObject())) {
508         LOG_ERROR("fail to Marshalling");
509         return false;
510     }
511 
512     MessageParcel reply;
513     MessageOption option;
514     int32_t result = Remote()->SendRequest(
515         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_REGISTER_OBSERVER), data, reply, option);
516     if (result != ERR_NONE) {
517         LOG_ERROR("SendRequest error, result=%{public}d", result);
518         return false;
519     }
520     return true;
521 }
522 
UnregisterObserver(const Uri & uri,const sptr<AAFwk::IDataAbilityObserver> & dataObserver)523 bool DataShareProxy::UnregisterObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver)
524 {
525     MessageParcel data;
526     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
527         LOG_ERROR("WriteInterfaceToken failed");
528         return false;
529     }
530     if (!ITypesUtil::Marshal(data, uri, dataObserver->AsObject())) {
531         LOG_ERROR("fail to Marshalling");
532         return false;
533     }
534 
535     MessageParcel reply;
536     MessageOption option;
537     int32_t result = Remote()->SendRequest(
538         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UNREGISTER_OBSERVER), data, reply, option);
539     if (result != ERR_NONE) {
540         LOG_ERROR("SendRequest error, result=%{public}d", result);
541         return false;
542     }
543     return true;
544 }
545 
NotifyChange(const Uri & uri)546 bool DataShareProxy::NotifyChange(const Uri &uri)
547 {
548     MessageParcel data;
549     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
550         LOG_ERROR("WriteInterfaceToken failed");
551         return false;
552     }
553     if (!ITypesUtil::Marshal(data, uri)) {
554         LOG_ERROR("fail to Marshalling");
555         return false;
556     }
557 
558     MessageParcel reply;
559     MessageOption option;
560     int32_t result = Remote()->SendRequest(
561         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_NOTIFY_CHANGE), data, reply, option);
562     if (result != ERR_NONE) {
563         LOG_ERROR("SendRequest error, result=%{public}d", result);
564         return false;
565     }
566     return true;
567 }
568 
NormalizeUri(const Uri & uri)569 Uri DataShareProxy::NormalizeUri(const Uri &uri)
570 {
571     MessageParcel data;
572     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
573         LOG_ERROR("WriteInterfaceToken failed");
574         return Uri("");
575     }
576     if (!ITypesUtil::Marshal(data, uri)) {
577         LOG_ERROR("fail to Marshalling");
578         return Uri("");
579     }
580 
581     MessageParcel reply;
582     MessageOption option;
583     int32_t err = Remote()->SendRequest(
584         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_NORMALIZE_URI), data, reply, option);
585     if (err != E_OK) {
586         LOG_ERROR("NormalizeUri fail to SendRequest. err: %{public}d", err);
587         return Uri("");
588     }
589     Uri info("");
590     if (!ITypesUtil::Unmarshal(reply, info)) {
591         LOG_ERROR("fail to Unmarshal index");
592         return Uri("");
593     }
594     return info;
595 }
596 
DenormalizeUri(const Uri & uri)597 Uri DataShareProxy::DenormalizeUri(const Uri &uri)
598 {
599     MessageParcel data;
600     if (!data.WriteInterfaceToken(DataShareProxy::GetDescriptor())) {
601         LOG_ERROR("WriteInterfaceToken failed");
602         return Uri("");
603     }
604 
605     if (!ITypesUtil::Marshal(data, uri)) {
606         LOG_ERROR("fail to Marshalling");
607         return Uri("");
608     }
609 
610     MessageParcel reply;
611     MessageOption option;
612     int32_t err = Remote()->SendRequest(
613         static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DENORMALIZE_URI), data, reply, option);
614     if (err != E_OK) {
615         LOG_ERROR("DenormalizeUri fail to SendRequest. err: %{public}d", err);
616         return Uri("");
617     }
618 
619     Uri info("");
620     if (!ITypesUtil::Unmarshal(reply, info)) {
621         LOG_ERROR("fail to Unmarshal index");
622         return Uri("");
623     }
624     return info;
625 }
626 
CheckSize(const UpdateOperations & operations)627 bool DataShareProxy::CheckSize(const UpdateOperations &operations)
628 {
629     size_t size = 0;
630     for (const auto &it : operations) {
631         size += it.second.size();
632     }
633     if (size > MAX_SIZE) {
634         LOG_ERROR("operations size greater than limit");
635         return false;
636     }
637     return true;
638 }
639 } // namespace DataShare
640 } // namespace OHOS
641