• 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 "ipc/cloud_sync_service_stub.h"
16 #include "cloud_file_sync_service_interface_code.h"
17 #include "data_sync/task_state_manager.h"
18 #include "dfs_error.h"
19 #include "dfsu_access_token_helper.h"
20 #include "dfsu_memory_guard.h"
21 #include "utils_log.h"
22 
23 namespace OHOS::FileManagement::CloudSync {
24 using namespace std;
25 
CloudSyncServiceStub()26 CloudSyncServiceStub::CloudSyncServiceStub()
27 {
28     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UNREGISTER_CALLBACK)] =
29         &CloudSyncServiceStub::HandleUnRegisterCallbackInner;
30     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_CALLBACK)] =
31         &CloudSyncServiceStub::HandleRegisterCallbackInner;
32     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_SYNC)] =
33         &CloudSyncServiceStub::HandleStartSyncInner;
34     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_TRIGGER_SYNC)] =
35         &CloudSyncServiceStub::HandleTriggerSyncInner;
36     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_STOP_SYNC)] =
37         &CloudSyncServiceStub::HandleStopSyncInner;
38     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CHANGE_APP_SWITCH)] =
39         &CloudSyncServiceStub::HandleChangeAppSwitch;
40     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CLEAN)] =
41         &CloudSyncServiceStub::HandleClean;
42     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_NOTIFY_DATA_CHANGE)] =
43         &CloudSyncServiceStub::HandleNotifyDataChange;
44     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_NOTIFY_EVENT_CHANGE)] =
45         &CloudSyncServiceStub::HandleNotifyEventChange;
46     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_ENABLE_CLOUD)] =
47         &CloudSyncServiceStub::HandleEnableCloud;
48     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DISABLE_CLOUD)] =
49         &CloudSyncServiceStub::HandleDisableCloud;
50     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_DOWNLOAD_FILE)] =
51         &CloudSyncServiceStub::HandleStartDownloadFile;
52     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_STOP_DOWNLOAD_FILE)] =
53         &CloudSyncServiceStub::HandleStopDownloadFile;
54     opToInterfaceMap_[static_cast<uint32_t>(
55         CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_DOWNLOAD_FILE_CALLBACK)] =
56         &CloudSyncServiceStub::HandleRegisterDownloadFileCallback;
57     opToInterfaceMap_[static_cast<uint32_t>(
58         CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UNREGISTER_DOWNLOAD_FILE_CALLBACK)] =
59         &CloudSyncServiceStub::HandleUnregisterDownloadFileCallback;
60     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UPLOAD_ASSET)] =
61         &CloudSyncServiceStub::HandleUploadAsset;
62     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DOWNLOAD_FILE)] =
63         &CloudSyncServiceStub::HandleDownloadFile;
64     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DOWNLOAD_ASSET)] =
65         &CloudSyncServiceStub::HandleDownloadAsset;
66     opToInterfaceMap_[static_cast<uint32_t>(
67         CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_DOWNLOAD_ASSET_CALLBACK)] =
68         &CloudSyncServiceStub::HandleRegisterDownloadAssetCallback;
69     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DELETE_ASSET)] =
70         &CloudSyncServiceStub::HandleDeleteAsset;
71     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_GET_SYNC_TIME)] =
72         &CloudSyncServiceStub::HandleGetSyncTime;
73     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CLEAN_CACHE)] =
74         &CloudSyncServiceStub::HandleCleanCache;
75     opToInterfaceMap_[static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_FILE_CACHE)] =
76         &CloudSyncServiceStub::HandleStartFileCache;
77 }
78 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)79 int32_t CloudSyncServiceStub::OnRemoteRequest(uint32_t code,
80                                               MessageParcel &data,
81                                               MessageParcel &reply,
82                                               MessageOption &option)
83 {
84     DfsuMemoryGuard cacheGuard;
85     TaskStateManager::GetInstance().StartTask();
86     if (data.ReadInterfaceToken() != GetDescriptor()) {
87         return E_SERVICE_DESCRIPTOR_IS_EMPTY;
88     }
89     auto interfaceIndex = opToInterfaceMap_.find(code);
90     if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
91         LOGE("Cannot response request %d: unknown tranction", code);
92         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
93     }
94     return (this->*(interfaceIndex->second))(data, reply);
95 }
96 
HandleUnRegisterCallbackInner(MessageParcel & data,MessageParcel & reply)97 int32_t CloudSyncServiceStub::HandleUnRegisterCallbackInner(MessageParcel &data, MessageParcel &reply)
98 {
99     LOGI("Begin UnRegisterCallbackInner");
100     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
101         LOGE("permission denied");
102         return E_PERMISSION_DENIED;
103     }
104     if (!DfsuAccessTokenHelper::IsSystemApp()) {
105         LOGE("caller hap is not system hap");
106         return E_PERMISSION_SYSTEM;
107     }
108 
109     int32_t res = UnRegisterCallbackInner();
110     reply.WriteInt32(res);
111     LOGI("End UnRegisterCallbackInner");
112     return res;
113 }
114 
HandleRegisterCallbackInner(MessageParcel & data,MessageParcel & reply)115 int32_t CloudSyncServiceStub::HandleRegisterCallbackInner(MessageParcel &data, MessageParcel &reply)
116 {
117     LOGI("Begin RegisterCallbackInner");
118     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
119         LOGE("permission denied");
120         return E_PERMISSION_DENIED;
121     }
122     if (!DfsuAccessTokenHelper::IsSystemApp()) {
123         LOGE("caller hap is not system hap");
124         return E_PERMISSION_SYSTEM;
125     }
126     auto remoteObj = data.ReadRemoteObject();
127     int32_t res = RegisterCallbackInner(remoteObj);
128     reply.WriteInt32(res);
129     LOGI("End RegisterCallbackInner");
130     return res;
131 }
132 
HandleStartSyncInner(MessageParcel & data,MessageParcel & reply)133 int32_t CloudSyncServiceStub::HandleStartSyncInner(MessageParcel &data, MessageParcel &reply)
134 {
135     LOGI("Begin StartSyncInner");
136     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
137         LOGE("permission denied");
138         return E_PERMISSION_DENIED;
139     }
140     if (!DfsuAccessTokenHelper::IsSystemApp()) {
141         LOGE("caller hap is not system hap");
142         return E_PERMISSION_SYSTEM;
143     }
144     auto forceFlag = data.ReadBool();
145     int32_t res = StartSyncInner(forceFlag);
146     reply.WriteInt32(res);
147     LOGI("End StartSyncInner");
148     return res;
149 }
150 
HandleTriggerSyncInner(MessageParcel & data,MessageParcel & reply)151 int32_t CloudSyncServiceStub::HandleTriggerSyncInner(MessageParcel &data, MessageParcel &reply)
152 {
153     LOGI("Begin TriggerSyncInner");
154     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
155         LOGE("permission denied");
156         return E_PERMISSION_DENIED;
157     }
158     if (!DfsuAccessTokenHelper::IsSystemApp()) {
159         LOGE("caller hap is not system hap");
160         return E_PERMISSION_SYSTEM;
161     }
162     string bundleName = data.ReadString();
163     int32_t userId = data.ReadInt32();
164     int32_t res = TriggerSyncInner(bundleName, userId);
165     reply.WriteInt32(res);
166     LOGI("End TriggerSyncInner");
167     return res;
168 }
169 
HandleStopSyncInner(MessageParcel & data,MessageParcel & reply)170 int32_t CloudSyncServiceStub::HandleStopSyncInner(MessageParcel &data, MessageParcel &reply)
171 {
172     LOGI("Begin StopSyncInner");
173     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
174         LOGE("permission denied");
175         return E_PERMISSION_DENIED;
176     }
177     if (!DfsuAccessTokenHelper::IsSystemApp()) {
178         LOGE("caller hap is not system hap");
179         return E_PERMISSION_SYSTEM;
180     }
181     int32_t res = StopSyncInner();
182     reply.WriteInt32(res);
183     LOGI("End StopSyncInner");
184     return res;
185 }
186 
HandleChangeAppSwitch(MessageParcel & data,MessageParcel & reply)187 int32_t CloudSyncServiceStub::HandleChangeAppSwitch(MessageParcel &data, MessageParcel &reply)
188 {
189     LOGI("Begin ChangeAppSwitch");
190     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
191         LOGE("permission denied");
192         return E_PERMISSION_DENIED;
193     }
194     if (!DfsuAccessTokenHelper::IsSystemApp()) {
195         LOGE("caller hap is not system hap");
196         return E_PERMISSION_SYSTEM;
197     }
198     string accountId = data.ReadString();
199     string bundleName = data.ReadString();
200     bool status = data.ReadBool();
201     int32_t res = ChangeAppSwitch(accountId, bundleName, status);
202     reply.WriteInt32(res);
203     LOGI("End ChangeAppSwitch");
204     return res;
205 }
206 
HandleClean(MessageParcel & data,MessageParcel & reply)207 int32_t CloudSyncServiceStub::HandleClean(MessageParcel &data, MessageParcel &reply)
208 {
209     LOGI("Begin Clean");
210     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
211         LOGE("permission denied");
212         return E_PERMISSION_DENIED;
213     }
214     if (!DfsuAccessTokenHelper::IsSystemApp()) {
215         LOGE("caller hap is not system hap");
216         return E_PERMISSION_SYSTEM;
217     }
218     string accountId = data.ReadString();
219     sptr<CleanOptions> options = data.ReadParcelable<CleanOptions>();
220     if (!options) {
221         LOGE("object of CleanOptions is nullptr");
222         return E_INVAL_ARG;
223     }
224     int32_t res = Clean(accountId, *options);
225     reply.WriteInt32(res);
226     LOGI("End Clean");
227     return res;
228 }
229 
HandleNotifyDataChange(MessageParcel & data,MessageParcel & reply)230 int32_t CloudSyncServiceStub::HandleNotifyDataChange(MessageParcel &data, MessageParcel &reply)
231 {
232     LOGI("Begin NotifyDataChange");
233     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
234         LOGE("permission denied");
235         return E_PERMISSION_DENIED;
236     }
237     if (!DfsuAccessTokenHelper::IsSystemApp()) {
238         LOGE("caller hap is not system hap");
239         return E_PERMISSION_SYSTEM;
240     }
241     string accountId = data.ReadString();
242     string bundleName = data.ReadString();
243     int32_t res = NotifyDataChange(accountId, bundleName);
244     reply.WriteInt32(res);
245     LOGI("End NotifyDataChange");
246     return res;
247 }
248 
HandleNotifyEventChange(MessageParcel & data,MessageParcel & reply)249 int32_t CloudSyncServiceStub::HandleNotifyEventChange(MessageParcel &data, MessageParcel &reply)
250 {
251     LOGI("Begin NotifyEventChange");
252     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
253         LOGE("permission denied");
254         return E_PERMISSION_DENIED;
255     }
256     if (!DfsuAccessTokenHelper::IsSystemApp()) {
257         LOGE("caller hap is not system hap");
258         return E_PERMISSION_SYSTEM;
259     }
260     int32_t userId = data.ReadInt32();
261     string eventIdStr = data.ReadString();
262     string extraDataStr = data.ReadString();
263 
264     int32_t res = NotifyEventChange(userId, eventIdStr, extraDataStr);
265     reply.WriteInt32(res);
266     LOGI("End NotifyEventChange");
267     return res;
268 }
269 
HandleDisableCloud(MessageParcel & data,MessageParcel & reply)270 int32_t CloudSyncServiceStub::HandleDisableCloud(MessageParcel &data, MessageParcel &reply)
271 {
272     LOGI("Begin DisableCloud");
273     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
274         LOGE("permission denied");
275         return E_PERMISSION_DENIED;
276     }
277     if (!DfsuAccessTokenHelper::IsSystemApp()) {
278         LOGE("caller hap is not system hap");
279         return E_PERMISSION_SYSTEM;
280     }
281     string accountId = data.ReadString();
282     int32_t res = DisableCloud(accountId);
283     reply.WriteInt32(res);
284     LOGI("End DisableCloud");
285     return res;
286 }
HandleEnableCloud(MessageParcel & data,MessageParcel & reply)287 int32_t CloudSyncServiceStub::HandleEnableCloud(MessageParcel &data, MessageParcel &reply)
288 {
289     LOGI("Begin EnableCloud");
290     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) {
291         LOGE("permission denied");
292         return E_PERMISSION_DENIED;
293     }
294     if (!DfsuAccessTokenHelper::IsSystemApp()) {
295         LOGE("caller hap is not system hap");
296         return E_PERMISSION_SYSTEM;
297     }
298     string accountId = data.ReadString();
299     sptr<SwitchDataObj> switchObj = data.ReadParcelable<SwitchDataObj>();
300     if (!switchObj) {
301         LOGE("object of SwitchDataObj is nullptr");
302         return E_INVAL_ARG;
303     }
304     int32_t res = EnableCloud(accountId, *switchObj);
305     reply.WriteInt32(res);
306     LOGI("End EnableCloud");
307     return res;
308 }
309 
HandleStartDownloadFile(MessageParcel & data,MessageParcel & reply)310 int32_t CloudSyncServiceStub::HandleStartDownloadFile(MessageParcel &data, MessageParcel &reply)
311 {
312     LOGI("Begin HandleStartDownloadFile");
313     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
314         LOGE("permission denied");
315         return E_PERMISSION_DENIED;
316     }
317     if (!DfsuAccessTokenHelper::IsSystemApp()) {
318         LOGE("caller hap is not system hap");
319         return E_PERMISSION_SYSTEM;
320     }
321     string path = data.ReadString();
322 
323     int32_t res = StartDownloadFile(path);
324     reply.WriteInt32(res);
325     LOGI("End HandleStartDownloadFile");
326     return res;
327 }
328 
HandleStartFileCache(MessageParcel & data,MessageParcel & reply)329 int32_t CloudSyncServiceStub::HandleStartFileCache(MessageParcel &data, MessageParcel &reply)
330 {
331     LOGI("Begin HandleStartFileCache");
332     string path = data.ReadString();
333     if (!DfsuAccessTokenHelper::CheckUriPermission(path) &&
334         !DfsuAccessTokenHelper::CheckCallerPermission(PERM_AUTH_URI)) {
335         LOGE("permission denied");
336         return E_PERMISSION_DENIED;
337     }
338     int32_t res = StartDownloadFile(path);
339     reply.WriteInt32(res);
340     LOGI("End HandleStartFileCache");
341     return res;
342 }
343 
HandleStopDownloadFile(MessageParcel & data,MessageParcel & reply)344 int32_t CloudSyncServiceStub::HandleStopDownloadFile(MessageParcel &data, MessageParcel &reply)
345 {
346     LOGI("Begin HandleStopDownloadFile");
347     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
348         LOGE("permission denied");
349         return E_PERMISSION_DENIED;
350     }
351     if (!DfsuAccessTokenHelper::IsSystemApp()) {
352         LOGE("caller hap is not system hap");
353         return E_PERMISSION_SYSTEM;
354     }
355     string path = data.ReadString();
356 
357     int32_t res = StopDownloadFile(path);
358     reply.WriteInt32(res);
359     LOGI("End HandleStopDownloadFile");
360     return res;
361 }
362 
HandleRegisterDownloadFileCallback(MessageParcel & data,MessageParcel & reply)363 int32_t CloudSyncServiceStub::HandleRegisterDownloadFileCallback(MessageParcel &data, MessageParcel &reply)
364 {
365     LOGI("Begin HandleRegisterDownloadFileCallback");
366     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
367         LOGE("permission denied");
368         return E_PERMISSION_DENIED;
369     }
370     if (!DfsuAccessTokenHelper::IsSystemApp()) {
371         LOGE("caller hap is not system hap");
372         return E_PERMISSION_SYSTEM;
373     }
374 
375     auto downloadCallback = data.ReadRemoteObject();
376 
377     int32_t res = RegisterDownloadFileCallback(downloadCallback);
378     reply.WriteInt32(res);
379     LOGI("End HandleRegisterDownloadFileCallback");
380     return res;
381 }
382 
HandleUnregisterDownloadFileCallback(MessageParcel & data,MessageParcel & reply)383 int32_t CloudSyncServiceStub::HandleUnregisterDownloadFileCallback(MessageParcel &data, MessageParcel &reply)
384 {
385     LOGI("Begin HandleUnregisterDownloadFileCallback");
386     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
387         LOGE("permission denied");
388         return E_PERMISSION_DENIED;
389     }
390     if (!DfsuAccessTokenHelper::IsSystemApp()) {
391         LOGE("caller hap is not system hap");
392         return E_PERMISSION_SYSTEM;
393     }
394 
395     int32_t res = UnregisterDownloadFileCallback();
396     reply.WriteInt32(res);
397     LOGI("End HandleUnregisterDownloadFileCallback");
398     return res;
399 }
400 
HandleUploadAsset(MessageParcel & data,MessageParcel & reply)401 int32_t CloudSyncServiceStub::HandleUploadAsset(MessageParcel &data, MessageParcel &reply)
402 {
403     LOGI("Begin UploadAsset");
404     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
405         LOGE("permission denied");
406         return E_PERMISSION_DENIED;
407     }
408     if (!DfsuAccessTokenHelper::IsSystemApp()) {
409         LOGE("caller hap is not system hap");
410         return E_PERMISSION_SYSTEM;
411     }
412     int32_t userId = data.ReadInt32();
413     string request = data.ReadString();
414     string result;
415     int32_t res = UploadAsset(userId, request, result);
416     reply.WriteInt32(res);
417     reply.WriteString(result);
418     LOGI("End UploadAsset");
419     return res;
420 }
421 
HandleDownloadFile(MessageParcel & data,MessageParcel & reply)422 int32_t CloudSyncServiceStub::HandleDownloadFile(MessageParcel &data, MessageParcel &reply)
423 {
424     LOGI("Begin DownloadFile");
425     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
426         LOGE("permission denied");
427         return E_PERMISSION_DENIED;
428     }
429     if (!DfsuAccessTokenHelper::IsSystemApp()) {
430         LOGE("caller hap is not system hap");
431         return E_PERMISSION_SYSTEM;
432     }
433     int32_t userId = data.ReadInt32();
434     string bundleName = data.ReadString();
435     sptr<AssetInfoObj> assetInfoObj = data.ReadParcelable<AssetInfoObj>();
436     if (!assetInfoObj) {
437         LOGE("object of AssetInfoObj is nullptr");
438         return E_INVAL_ARG;
439     }
440     int32_t res = DownloadFile(userId, bundleName, *assetInfoObj);
441     reply.WriteInt32(res);
442     LOGI("End DownloadFile");
443     return res;
444 }
445 
HandleDownloadAsset(MessageParcel & data,MessageParcel & reply)446 int32_t CloudSyncServiceStub::HandleDownloadAsset(MessageParcel &data, MessageParcel &reply)
447 {
448     LOGI("Begin DownloadAsset");
449     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
450         LOGE("permission denied");
451         return E_PERMISSION_DENIED;
452     }
453     if (!DfsuAccessTokenHelper::IsSystemApp()) {
454         LOGE("caller hap is not system hap");
455         return E_PERMISSION_SYSTEM;
456     }
457     uint64_t taskId = data.ReadUint64();
458     int32_t userId = data.ReadInt32();
459     string bundleName = data.ReadString();
460     string networkId = data.ReadString();
461     sptr<AssetInfoObj> assetInfoObj = data.ReadParcelable<AssetInfoObj>();
462     if (!assetInfoObj) {
463         LOGE("object of AssetInfoObj is nullptr");
464         return E_INVAL_ARG;
465     }
466     int32_t res = DownloadAsset(taskId, userId, bundleName, networkId, * assetInfoObj);
467     reply.WriteInt32(res);
468     LOGI("End DownloadAsset");
469     return res;
470 }
471 
HandleRegisterDownloadAssetCallback(MessageParcel & data,MessageParcel & reply)472 int32_t CloudSyncServiceStub::HandleRegisterDownloadAssetCallback(MessageParcel &data, MessageParcel &reply)
473 {
474     LOGI("Begin RegisterDownloadAssetCallback");
475     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
476         LOGE("permission denied");
477         return E_PERMISSION_DENIED;
478     }
479     if (!DfsuAccessTokenHelper::IsSystemApp()) {
480         LOGE("caller hap is not system hap");
481         return E_PERMISSION_SYSTEM;
482     }
483     auto remoteObj = data.ReadRemoteObject();
484     int32_t res = RegisterDownloadAssetCallback(remoteObj);
485     reply.WriteInt32(res);
486     LOGI("End RegisterDownloadAssetCallback");
487     return res;
488 }
489 
HandleDeleteAsset(MessageParcel & data,MessageParcel & reply)490 int32_t CloudSyncServiceStub::HandleDeleteAsset(MessageParcel &data, MessageParcel &reply)
491 {
492     LOGI("Begin DeleteAsset");
493     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
494         LOGE("permission denied");
495         return E_PERMISSION_DENIED;
496     }
497     if (!DfsuAccessTokenHelper::IsSystemApp()) {
498         LOGE("caller hap is not system hap");
499         return E_PERMISSION_SYSTEM;
500     }
501     int32_t userId = data.ReadInt32();
502     string uri = data.ReadString();
503     int32_t res = DeleteAsset(userId, uri);
504     reply.WriteInt32(res);
505     reply.WriteString(uri);
506     LOGI("End DeleteAsset");
507     return res;
508 }
509 
HandleGetSyncTime(MessageParcel & data,MessageParcel & reply)510 int32_t CloudSyncServiceStub::HandleGetSyncTime(MessageParcel &data, MessageParcel &reply)
511 {
512     LOGI("Begin GetSyncTime");
513     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
514         LOGE("permission denied");
515         return E_PERMISSION_DENIED;
516     }
517     if (!DfsuAccessTokenHelper::IsSystemApp()) {
518         LOGE("caller hap is not system hap");
519         return E_PERMISSION_SYSTEM;
520     }
521 
522     int64_t syncTime = 0;
523     int32_t res = GetSyncTimeInner(syncTime);
524     reply.WriteInt64(syncTime);
525     reply.WriteInt32(res);
526     return res;
527 }
528 
HandleCleanCache(MessageParcel & data,MessageParcel & reply)529 int32_t CloudSyncServiceStub::HandleCleanCache(MessageParcel &data, MessageParcel &reply)
530 {
531     LOGI("Begin HandleCleanCache");
532     if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC)) {
533         LOGE("permission denied");
534         return E_PERMISSION_DENIED;
535     }
536     if (!DfsuAccessTokenHelper::IsSystemApp()) {
537         LOGE("caller hap is not system hap");
538         return E_PERMISSION_SYSTEM;
539     }
540 
541     string uri = data.ReadString();
542     int32_t res = CleanCacheInner(uri);
543 
544     reply.WriteInt32(res);
545     return res;
546 }
547 } // namespace OHOS::FileManagement::CloudSync
548