1 /*
2 * Copyright (c) 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 "datashare_stub.h"
17
18 #include <cinttypes>
19
20 #include "data_ability_observer_interface.h"
21 #include "datashare_itypes_utils.h"
22 #include "datashare_log.h"
23 #include "ipc_skeleton.h"
24 #include "ipc_types.h"
25 #include "ishared_result_set.h"
26 #include "datashare_operation_statement.h"
27 #include "unistd.h"
28 #include "string_ex.h"
29
30 using namespace OHOS::DistributedShare::DataShare;
31
32 namespace OHOS {
33 namespace DataShare {
34 constexpr int DEFAULT_NUMBER = -1;
35 constexpr int PERMISSION_ERROR_NUMBER = -2;
DataShareStub()36 DataShareStub::DataShareStub()
37 {
38 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_GET_FILE_TYPES)] = &DataShareStub::CmdGetFileTypes;
39 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_OPEN_FILE)] = &DataShareStub::CmdOpenFile;
40 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_OPEN_RAW_FILE)] = &DataShareStub::CmdOpenRawFile;
41 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT)] = &DataShareStub::CmdInsert;
42 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UPDATE)] = &DataShareStub::CmdUpdate;
43 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DELETE)] = &DataShareStub::CmdDelete;
44 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_QUERY)] = &DataShareStub::CmdQuery;
45 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_GET_TYPE)] = &DataShareStub::CmdGetType;
46 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_BATCH_INSERT)] = &DataShareStub::CmdBatchInsert;
47 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_REGISTER_OBSERVER)] =
48 &DataShareStub::CmdRegisterObserver;
49 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UNREGISTER_OBSERVER)] =
50 &DataShareStub::CmdUnregisterObserver;
51 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_NOTIFY_CHANGE)] = &DataShareStub::CmdNotifyChange;
52 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_NORMALIZE_URI)] = &DataShareStub::CmdNormalizeUri;
53 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DENORMALIZE_URI)] =
54 &DataShareStub::CmdDenormalizeUri;
55 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_EXECUTE_BATCH)] = &DataShareStub::CmdExecuteBatch;
56 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT_EXT)] = &DataShareStub::CmdInsertExt;
57 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_BATCH_UPDATE)] = &DataShareStub::CmdBatchUpdate;
58 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_INSERT_EX)] = &DataShareStub::CmdInsertEx;
59 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_UPDATE_EX)] = &DataShareStub::CmdUpdateEx;
60 stubFuncMap_[static_cast<uint32_t>(IDataShareInterfaceCode::CMD_DELETE_EX)] = &DataShareStub::CmdDeleteEx;
61 }
62
~DataShareStub()63 DataShareStub::~DataShareStub()
64 {
65 stubFuncMap_.clear();
66 }
67
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)68 int DataShareStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
69 MessageOption& option)
70 {
71 std::u16string descriptor = DataShareStub::GetDescriptor();
72 std::u16string remoteDescriptor = data.ReadInterfaceToken();
73 if (descriptor != remoteDescriptor) {
74 LOG_INFO("local descriptor is not equal to remote, localDescriptor = %{public}s, remoteDescriptor = %{public}s",
75 Str16ToStr8(descriptor).c_str(), Str16ToStr8(remoteDescriptor).c_str());
76 return ERR_INVALID_STATE;
77 }
78
79 const auto &itFunc = stubFuncMap_.find(code);
80 auto start = std::chrono::steady_clock::now();
81 int32_t ret = 0;
82 bool isCodeValid = false;
83 if (itFunc != stubFuncMap_.end()) {
84 isCodeValid = true;
85 ret = (this->*(itFunc->second))(data, reply);
86 } else if (code == static_cast<uint32_t>(IDataShareInterfaceCode::CMD_USER_DEFINE_FUNC)) {
87 isCodeValid = true;
88 ret = CmdUserDefineFunc(data, reply, option);
89 }
90 if (isCodeValid) {
91 auto finish = std::chrono::steady_clock::now();
92 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start);
93 if (duration >= TIME_THRESHOLD) {
94 auto callingPid = IPCSkeleton::GetCallingPid();
95 int64_t milliseconds = duration.count();
96 LOG_ERROR("extension time over, code:%{public}u callingPid:%{public}d, cost:%{public}" PRIi64 "ms",
97 code, callingPid, milliseconds);
98 }
99 return ret;
100 }
101 LOG_DEBUG("remote request unhandled: %{public}d", code);
102 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
103 }
104
CmdGetFileTypes(MessageParcel & data,MessageParcel & reply)105 ErrCode DataShareStub::CmdGetFileTypes(MessageParcel &data, MessageParcel &reply)
106 {
107 Uri uri("");
108 std::string mimeTypeFilter;
109 if (!ITypesUtil::Unmarshal(data, uri, mimeTypeFilter)) {
110 LOG_ERROR("Unmarshalling value is nullptr");
111 return ERR_INVALID_VALUE;
112 }
113 if (mimeTypeFilter.empty()) {
114 LOG_ERROR("mimeTypeFilter is nullptr");
115 return ERR_INVALID_VALUE;
116 }
117 std::vector<std::string> types = GetFileTypes(uri, mimeTypeFilter);
118 if (!ITypesUtil::Marshal(reply, types)) {
119 LOG_ERROR("Marshal value is nullptr");
120 return ERR_INVALID_VALUE;
121 }
122 return E_OK;
123 }
124
CmdOpenFile(MessageParcel & data,MessageParcel & reply)125 ErrCode DataShareStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply)
126 {
127 Uri uri("");
128 std::string mode;
129 if (!ITypesUtil::Unmarshal(data, uri, mode)) {
130 LOG_ERROR("Unmarshalling value is nullptr");
131 return ERR_INVALID_VALUE;
132 }
133 if (mode.empty()) {
134 LOG_ERROR("mode is nullptr");
135 return ERR_INVALID_VALUE;
136 }
137 int fd = OpenFile(uri, mode);
138 if (fd < 0) {
139 return ERR_INVALID_DATA;
140 }
141 if (!reply.WriteFileDescriptor(fd)) {
142 LOG_ERROR("fail to WriteFileDescriptor fd");
143 close(fd);
144 return ERR_INVALID_VALUE;
145 }
146 close(fd);
147 return E_OK;
148 }
149
CmdOpenRawFile(MessageParcel & data,MessageParcel & reply)150 ErrCode DataShareStub::CmdOpenRawFile(MessageParcel &data, MessageParcel &reply)
151 {
152 Uri uri("");
153 std::string mode;
154 if (!ITypesUtil::Unmarshal(data, uri, mode)) {
155 LOG_ERROR("Unmarshalling value is nullptr");
156 return ERR_INVALID_VALUE;
157 }
158 int fd = OpenRawFile(uri, mode);
159 if (!ITypesUtil::Marshal(reply, fd)) {
160 LOG_ERROR("Marshal value is nullptr");
161 return ERR_INVALID_VALUE;
162 }
163 return E_OK;
164 }
165
CmdInsert(MessageParcel & data,MessageParcel & reply)166 ErrCode DataShareStub::CmdInsert(MessageParcel &data, MessageParcel &reply)
167 {
168 Uri uri("");
169 DataShareValuesBucket value;
170 if (!ITypesUtil::Unmarshal(data, uri, value)) {
171 LOG_ERROR("Unmarshalling value is nullptr");
172 return ERR_INVALID_VALUE;
173 }
174 int index = Insert(uri, value);
175 if (index == DEFAULT_NUMBER) {
176 LOG_ERROR("Insert inner error");
177 return ERR_INVALID_VALUE;
178 } else if (index == PERMISSION_ERROR_NUMBER) {
179 LOG_ERROR("Insert permission error");
180 return ERR_PERMISSION_DENIED;
181 }
182 if (!reply.WriteInt32(index)) {
183 LOG_ERROR("fail to WriteInt32 index");
184 return ERR_INVALID_VALUE;
185 }
186 return E_OK;
187 }
188
CmdUpdate(MessageParcel & data,MessageParcel & reply)189 ErrCode DataShareStub::CmdUpdate(MessageParcel &data, MessageParcel &reply)
190 {
191 Uri uri("");
192 DataSharePredicates predicates;
193 DataShareValuesBucket value;
194 if (!ITypesUtil::Unmarshal(data, uri, predicates, value)) {
195 LOG_ERROR("Unmarshalling predicates is nullptr");
196 return ERR_INVALID_VALUE;
197 }
198 int index = Update(uri, predicates, value);
199 if (index == DEFAULT_NUMBER) {
200 LOG_ERROR("Update inner error");
201 return ERR_INVALID_VALUE;
202 } else if (index == PERMISSION_ERROR_NUMBER) {
203 LOG_ERROR("Update permission error");
204 return ERR_PERMISSION_DENIED;
205 }
206 if (!reply.WriteInt32(index)) {
207 LOG_ERROR("fail to WriteInt32 index");
208 return ERR_INVALID_VALUE;
209 }
210 return E_OK;
211 }
212
CmdBatchUpdate(OHOS::MessageParcel & data,OHOS::MessageParcel & reply)213 ErrCode DataShareStub::CmdBatchUpdate(OHOS::MessageParcel &data, OHOS::MessageParcel &reply)
214 {
215 UpdateOperations updateOperations;
216 if (!ITypesUtil::Unmarshal(data, updateOperations)) {
217 LOG_ERROR("Unmarshalling updateOperations is nullptr");
218 return ERR_INVALID_VALUE;
219 }
220 std::vector<BatchUpdateResult> results;
221 int ret = BatchUpdate(updateOperations, results);
222 if (ret == DEFAULT_NUMBER) {
223 LOG_ERROR("BatchUpdate inner error, ret is %{public}d.", ret);
224 return ERR_INVALID_VALUE;
225 } else if (ret == PERMISSION_ERROR_NUMBER) {
226 LOG_ERROR("BatchUpdate permission error");
227 return ERR_PERMISSION_DENIED;
228 }
229 if (!ITypesUtil::Marshal(reply, results)) {
230 LOG_ERROR("marshalling updateOperations is failed");
231 return ERR_INVALID_VALUE;
232 }
233 return E_OK;
234 }
235
CmdDelete(MessageParcel & data,MessageParcel & reply)236 ErrCode DataShareStub::CmdDelete(MessageParcel &data, MessageParcel &reply)
237 {
238 Uri uri("");
239 DataSharePredicates predicates;
240 if (!ITypesUtil::Unmarshal(data, uri, predicates)) {
241 LOG_ERROR("Unmarshalling predicates is nullptr");
242 return ERR_INVALID_VALUE;
243 }
244 int index = Delete(uri, predicates);
245 if (index == DEFAULT_NUMBER) {
246 LOG_ERROR("Delete inner error");
247 return ERR_INVALID_VALUE;
248 } else if (index == PERMISSION_ERROR_NUMBER) {
249 LOG_ERROR("Delete permission error");
250 return ERR_PERMISSION_DENIED;
251 }
252 if (!reply.WriteInt32(index)) {
253 LOG_ERROR("fail to WriteInt32 index");
254 return ERR_INVALID_VALUE;
255 }
256 return E_OK;
257 }
258
CmdInsertEx(MessageParcel & data,MessageParcel & reply)259 ErrCode DataShareStub::CmdInsertEx(MessageParcel &data, MessageParcel &reply)
260 {
261 Uri uri("");
262 DataShareValuesBucket value;
263 if (!ITypesUtil::Unmarshal(data, uri, value)) {
264 LOG_ERROR("Unmarshalling value is nullptr");
265 return E_UNMARSHAL_ERROR;
266 }
267
268 auto [errCode, result] = InsertEx(uri, value);
269 if (errCode == DEFAULT_NUMBER) {
270 LOG_ERROR("Insert inner error");
271 return ERR_INVALID_VALUE;
272 } else if (errCode == PERMISSION_ERROR_NUMBER) {
273 LOG_ERROR("Insert permission error");
274 return ERR_PERMISSION_DENIED;
275 }
276
277 if (!ITypesUtil::Marshal(reply, errCode, result)) {
278 LOG_ERROR("Marshal value is nullptr");
279 return E_MARSHAL_ERROR;
280 }
281 return E_OK;
282 }
283
CmdUpdateEx(MessageParcel & data,MessageParcel & reply)284 ErrCode DataShareStub::CmdUpdateEx(MessageParcel &data, MessageParcel &reply)
285 {
286 Uri uri("");
287 DataSharePredicates predicates;
288 DataShareValuesBucket value;
289 if (!ITypesUtil::Unmarshal(data, uri, predicates, value)) {
290 LOG_ERROR("Unmarshalling predicates is nullptr");
291 return E_UNMARSHAL_ERROR;
292 }
293
294 auto [errCode, result] = UpdateEx(uri, predicates, value);
295 if (errCode == DEFAULT_NUMBER) {
296 LOG_ERROR("Update inner error");
297 return ERR_INVALID_VALUE;
298 } else if (errCode == PERMISSION_ERROR_NUMBER) {
299 LOG_ERROR("Update permission error");
300 return ERR_PERMISSION_DENIED;
301 }
302
303 if (!ITypesUtil::Marshal(reply, errCode, result)) {
304 LOG_ERROR("Marshal value is nullptr");
305 return E_MARSHAL_ERROR;
306 }
307 return E_OK;
308 }
309
CmdDeleteEx(MessageParcel & data,MessageParcel & reply)310 ErrCode DataShareStub::CmdDeleteEx(MessageParcel &data, MessageParcel &reply)
311 {
312 Uri uri("");
313 DataSharePredicates predicates;
314 if (!ITypesUtil::Unmarshal(data, uri, predicates)) {
315 LOG_ERROR("Unmarshalling predicates is nullptr");
316 return E_UNMARSHAL_ERROR;
317 }
318 auto [errCode, result] = DeleteEx(uri, predicates);
319 if (errCode == DEFAULT_NUMBER) {
320 LOG_ERROR("Delete inner error");
321 return ERR_INVALID_VALUE;
322 } else if (errCode == PERMISSION_ERROR_NUMBER) {
323 LOG_ERROR("Delete permission error");
324 return ERR_PERMISSION_DENIED;
325 }
326 if (!ITypesUtil::Marshal(reply, errCode, result)) {
327 LOG_ERROR("Marshal value is nullptr");
328 return E_MARSHAL_ERROR;
329 }
330 return E_OK;
331 }
332
CmdQuery(MessageParcel & data,MessageParcel & reply)333 ErrCode DataShareStub::CmdQuery(MessageParcel &data, MessageParcel &reply)
334 {
335 Uri uri("");
336 DataSharePredicates predicates;
337 std::vector<std::string> columns;
338 if (!ITypesUtil::Unmarshal(data, uri, columns)) {
339 LOG_ERROR("Unmarshalling uri and columns to data failed");
340 return ERR_INVALID_VALUE;
341 }
342 if (!ITypesUtil::UnmarshalPredicates(predicates, data)) {
343 LOG_ERROR("Unmarshalling predicates to shared-memory failed");
344 return ERR_INVALID_VALUE;
345 }
346 DatashareBusinessError businessError;
347 auto resultSet = Query(uri, predicates, columns, businessError);
348 auto result = ISharedResultSet::WriteToParcel(std::move(resultSet), reply);
349 reply.WriteInt32(businessError.GetCode());
350 reply.WriteString(businessError.GetMessage());
351 if (result == nullptr) {
352 LOG_ERROR("!resultSet->Marshalling(reply)");
353 return ERR_INVALID_VALUE;
354 }
355 return E_OK;
356 }
357
CmdGetType(MessageParcel & data,MessageParcel & reply)358 ErrCode DataShareStub::CmdGetType(MessageParcel &data, MessageParcel &reply)
359 {
360 Uri uri("");
361 if (!ITypesUtil::Unmarshal(data, uri)) {
362 LOG_ERROR("Unmarshalling predicates is nullptr");
363 return ERR_INVALID_VALUE;
364 }
365 std::string type = GetType(uri);
366 if (!reply.WriteString(type)) {
367 LOG_ERROR("fail to WriteString type");
368 return ERR_INVALID_VALUE;
369 }
370 return E_OK;
371 }
372
CmdUserDefineFunc(MessageParcel & data,MessageParcel & reply,MessageOption & option)373 ErrCode DataShareStub::CmdUserDefineFunc(MessageParcel &data, MessageParcel &reply, MessageOption &option)
374 {
375 UserDefineFunc(data, reply, option);
376 return E_OK;
377 }
378
CmdBatchInsert(MessageParcel & data,MessageParcel & reply)379 ErrCode DataShareStub::CmdBatchInsert(MessageParcel &data, MessageParcel &reply)
380 {
381 Uri uri("");
382 std::vector<DataShareValuesBucket> values;
383 if (!ITypesUtil::Unmarshal(data, uri)) {
384 LOG_ERROR("Unmarshalling uri from data failed");
385 return ERR_INVALID_VALUE;
386 }
387 if (!ITypesUtil::UnmarshalValuesBucketVec(values, data)) {
388 LOG_ERROR("Unmarshalling DataShareValuesBucket from shared-memory failed");
389 return ERR_INVALID_VALUE;
390 }
391 int ret = BatchInsert(uri, values);
392 if (ret == DEFAULT_NUMBER) {
393 LOG_ERROR("BatchInsert inner error");
394 return ERR_INVALID_VALUE;
395 } else if (ret == PERMISSION_ERROR_NUMBER) {
396 LOG_ERROR("BatchInsert permission error");
397 return ERR_PERMISSION_DENIED;
398 }
399 if (!reply.WriteInt32(ret)) {
400 LOG_ERROR("fail to WriteInt32 ret");
401 return ERR_INVALID_VALUE;
402 }
403 return E_OK;
404 }
405
CmdRegisterObserver(MessageParcel & data,MessageParcel & reply)406 ErrCode DataShareStub::CmdRegisterObserver(MessageParcel &data, MessageParcel &reply)
407 {
408 Uri uri("");
409 sptr<IRemoteObject> observer;
410 if (!ITypesUtil::Unmarshal(data, uri, observer)) {
411 LOG_ERROR("Unmarshalling predicates is nullptr");
412 return ERR_INVALID_VALUE;
413 }
414 auto obServer = iface_cast<AAFwk::IDataAbilityObserver>(observer);
415 if (obServer == nullptr) {
416 LOG_ERROR("obServer is nullptr");
417 return ERR_INVALID_VALUE;
418 }
419
420 bool ret = RegisterObserver(uri, obServer);
421 if (!reply.WriteInt32(ret)) {
422 LOG_ERROR("fail to WriteInt32 ret");
423 return ERR_INVALID_VALUE;
424 }
425 return E_OK;
426 }
427
CmdUnregisterObserver(MessageParcel & data,MessageParcel & reply)428 ErrCode DataShareStub::CmdUnregisterObserver(MessageParcel &data, MessageParcel &reply)
429 {
430 Uri uri("");
431 sptr<IRemoteObject> observer;
432 if (!ITypesUtil::Unmarshal(data, uri, observer)) {
433 LOG_ERROR("Unmarshalling predicates is nullptr");
434 return ERR_INVALID_VALUE;
435 }
436 auto obServer = iface_cast<AAFwk::IDataAbilityObserver>(observer);
437 if (obServer == nullptr) {
438 LOG_ERROR("obServer is nullptr");
439 return ERR_INVALID_VALUE;
440 }
441
442 bool ret = UnregisterObserver(uri, obServer);
443 if (!reply.WriteInt32(ret)) {
444 LOG_ERROR("fail to WriteInt32 ret");
445 return ERR_INVALID_VALUE;
446 }
447 return E_OK;
448 }
449
CmdNotifyChange(MessageParcel & data,MessageParcel & reply)450 ErrCode DataShareStub::CmdNotifyChange(MessageParcel &data, MessageParcel &reply)
451 {
452 Uri uri("");
453 if (!ITypesUtil::Unmarshal(data, uri)) {
454 LOG_ERROR("Unmarshalling predicates is nullptr");
455 return ERR_INVALID_VALUE;
456 }
457
458 bool ret = NotifyChange(uri);
459 if (!reply.WriteInt32(ret)) {
460 LOG_ERROR("fail to WriteInt32 ret");
461 return ERR_INVALID_VALUE;
462 }
463 return E_OK;
464 }
465
CmdNormalizeUri(MessageParcel & data,MessageParcel & reply)466 ErrCode DataShareStub::CmdNormalizeUri(MessageParcel &data, MessageParcel &reply)
467 {
468 Uri uri("");
469 if (!ITypesUtil::Unmarshal(data, uri)) {
470 LOG_ERROR("Unmarshalling predicates is nullptr");
471 return ERR_INVALID_VALUE;
472 }
473 auto ret = NormalizeUri(uri);
474 if (!ITypesUtil::Marshal(reply, ret)) {
475 LOG_ERROR("Write to message parcel failed!");
476 return ERR_INVALID_VALUE;
477 }
478 return E_OK;
479 }
480
CmdDenormalizeUri(MessageParcel & data,MessageParcel & reply)481 ErrCode DataShareStub::CmdDenormalizeUri(MessageParcel &data, MessageParcel &reply)
482 {
483 Uri uri("");
484 if (!ITypesUtil::Unmarshal(data, uri)) {
485 LOG_ERROR("Unmarshalling predicates is nullptr");
486 return ERR_INVALID_VALUE;
487 }
488
489 auto ret = DenormalizeUri(uri);
490 if (!ITypesUtil::Marshal(reply, ret)) {
491 LOG_ERROR("Write to message parcel failed!");
492 return ERR_INVALID_VALUE;
493 }
494 return E_OK;
495 }
496
CmdExecuteBatch(MessageParcel & data,MessageParcel & reply)497 ErrCode DataShareStub::CmdExecuteBatch(MessageParcel &data, MessageParcel &reply)
498 {
499 std::vector<OperationStatement> statements;
500 ExecResultSet result;
501 if (!ITypesUtil::Unmarshal(data, statements)) {
502 LOG_ERROR("Unmarshalling OperationStatement failed");
503 return ERR_INVALID_VALUE;
504 }
505 auto ret = ExecuteBatch(statements, result);
506 if (ret == DEFAULT_NUMBER) {
507 LOG_ERROR("ExecuteBatch error");
508 return ERR_INVALID_VALUE;
509 }
510 if (!ITypesUtil::Marshal(reply, result)) {
511 LOG_ERROR("fail to write result");
512 return ERR_INVALID_VALUE;
513 }
514 return E_OK;
515 }
516
CmdInsertExt(MessageParcel & data,MessageParcel & reply)517 ErrCode DataShareStub::CmdInsertExt(MessageParcel &data, MessageParcel &reply)
518 {
519 Uri uri("");
520 DataShareValuesBucket value;
521 if (!ITypesUtil::Unmarshal(data, uri, value)) {
522 LOG_ERROR("Unmarshalling value is nullptr");
523 return ERR_INVALID_VALUE;
524 }
525 std::string result;
526 int index = InsertExt(uri, value, result);
527 if (index == DEFAULT_NUMBER) {
528 LOG_ERROR("Insert inner error");
529 return ERR_INVALID_VALUE;
530 }
531 if (!ITypesUtil::Marshal(reply, index, result)) {
532 LOG_ERROR("fail to write result");
533 return ERR_INVALID_VALUE;
534 }
535 return E_OK;
536 }
537
ExecuteBatch(const std::vector<OperationStatement> & statements,ExecResultSet & result)538 int DataShareStub::ExecuteBatch(const std::vector<OperationStatement> &statements, ExecResultSet &result)
539 {
540 return 0;
541 }
542
InsertExt(const Uri & uri,const DataShareValuesBucket & value,std::string & result)543 int DataShareStub::InsertExt(const Uri &uri, const DataShareValuesBucket &value, std::string &result)
544 {
545 return 0;
546 }
547
BatchUpdate(const UpdateOperations & operations,std::vector<BatchUpdateResult> & results)548 int DataShareStub::BatchUpdate(const UpdateOperations &operations, std::vector<BatchUpdateResult> &results)
549 {
550 return 0;
551 }
InsertEx(const Uri & uri,const DataShareValuesBucket & value)552 std::pair<int32_t, int32_t> DataShareStub::InsertEx(const Uri &uri, const DataShareValuesBucket &value)
553 {
554 return std::make_pair(0, 0);
555 }
UpdateEx(const Uri & uri,const DataSharePredicates & predicates,const DataShareValuesBucket & value)556 std::pair<int32_t, int32_t> DataShareStub::UpdateEx(const Uri &uri, const DataSharePredicates &predicates,
557 const DataShareValuesBucket &value)
558 {
559 return std::make_pair(0, 0);
560 }
DeleteEx(const Uri & uri,const DataSharePredicates & predicates)561 std::pair<int32_t, int32_t> DataShareStub::DeleteEx(const Uri &uri, const DataSharePredicates &predicates)
562 {
563 return std::make_pair(0, 0);
564 }
565
UserDefineFunc(MessageParcel & data,MessageParcel & reply,MessageOption & option)566 int32_t DataShareStub::UserDefineFunc(
567 MessageParcel &data, MessageParcel &reply, MessageOption &option)
568 {
569 LOG_ERROR("UserDefineFunc excuted.");
570 return 0;
571 }
572 } // namespace DataShare
573 } // namespace OHOS