1cb7eb8c9Sopenharmony_ci/* 2cb7eb8c9Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3cb7eb8c9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb7eb8c9Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb7eb8c9Sopenharmony_ci * You may obtain a copy of the License at 6cb7eb8c9Sopenharmony_ci * 7cb7eb8c9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb7eb8c9Sopenharmony_ci * 9cb7eb8c9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb7eb8c9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb7eb8c9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb7eb8c9Sopenharmony_ci * See the License for the specific language governing permissions and 13cb7eb8c9Sopenharmony_ci * limitations under the License. 14cb7eb8c9Sopenharmony_ci */ 15cb7eb8c9Sopenharmony_ci#include "cloudsyncservicestub_fuzzer.h" 16cb7eb8c9Sopenharmony_ci 17cb7eb8c9Sopenharmony_ci#include <cstddef> 18cb7eb8c9Sopenharmony_ci#include <cstdint> 19cb7eb8c9Sopenharmony_ci#include <fcntl.h> 20cb7eb8c9Sopenharmony_ci#include <map> 21cb7eb8c9Sopenharmony_ci 22cb7eb8c9Sopenharmony_ci#include "accesstoken_kit.h" 23cb7eb8c9Sopenharmony_ci#include "cloud_file_sync_service_interface_code.h" 24cb7eb8c9Sopenharmony_ci#include "cloud_fuzzer_helper.h" 25cb7eb8c9Sopenharmony_ci#include "cloud_sync_service.h" 26cb7eb8c9Sopenharmony_ci#include "cloud_sync_service_stub.h" 27cb7eb8c9Sopenharmony_ci#include "i_cloud_download_callback.h" 28cb7eb8c9Sopenharmony_ci#include "i_cloud_sync_callback.h" 29cb7eb8c9Sopenharmony_ci#include "i_download_asset_callback.h" 30cb7eb8c9Sopenharmony_ci#include "task_state_manager.h" 31cb7eb8c9Sopenharmony_ci 32cb7eb8c9Sopenharmony_ci#include "message_parcel.h" 33cb7eb8c9Sopenharmony_ci#include "nativetoken_kit.h" 34cb7eb8c9Sopenharmony_ci#include "token_setproc.h" 35cb7eb8c9Sopenharmony_ci#include "utils_log.h" 36cb7eb8c9Sopenharmony_ci 37cb7eb8c9Sopenharmony_cinamespace OHOS { 38cb7eb8c9Sopenharmony_ciconstexpr size_t U32_AT_SIZE = 4; 39cb7eb8c9Sopenharmony_ciconstexpr size_t U64_AT_SIZE = 8; 40cb7eb8c9Sopenharmony_ciconstexpr size_t BOOL_AT_SIZE = 1; 41cb7eb8c9Sopenharmony_ciconstexpr int SPLITE_SIZE = 5; 42cb7eb8c9Sopenharmony_ciconst std::u16string CLOUD_SYNC_SERVICE_TOKEN = u"OHOS.Filemanagement.Dfs.ICloudSyncService"; 43cb7eb8c9Sopenharmony_ciconstexpr int32_t SERVICE_SA_ID = 5204; 44cb7eb8c9Sopenharmony_ci 45cb7eb8c9Sopenharmony_ciusing namespace OHOS::FileManagement::CloudSync; 46cb7eb8c9Sopenharmony_ciusing namespace std; 47cb7eb8c9Sopenharmony_ciclass ICloudSyncCallbackTest : public IRemoteStub<ICloudSyncCallback> { 48cb7eb8c9Sopenharmony_cipublic: 49cb7eb8c9Sopenharmony_ci void OnSyncStateChanged(SyncType type, SyncPromptState state) override {} 50cb7eb8c9Sopenharmony_ci void OnSyncStateChanged(CloudSyncState state, ErrorType error) override {} 51cb7eb8c9Sopenharmony_ci}; 52cb7eb8c9Sopenharmony_ci 53cb7eb8c9Sopenharmony_ciclass ICloudDownloadCallbackTest : public IRemoteStub<ICloudDownloadCallback> { 54cb7eb8c9Sopenharmony_cipublic: 55cb7eb8c9Sopenharmony_ci void OnDownloadProcess(const DownloadProgressObj &progress) override {} 56cb7eb8c9Sopenharmony_ci}; 57cb7eb8c9Sopenharmony_ci 58cb7eb8c9Sopenharmony_ciclass IDownloadAssetCallbackTest : public IRemoteStub<IDownloadAssetCallback> { 59cb7eb8c9Sopenharmony_cipublic: 60cb7eb8c9Sopenharmony_ci void OnFinished(const TaskId taskId, const std::string &uri, const int32_t result) override {} 61cb7eb8c9Sopenharmony_ci}; 62cb7eb8c9Sopenharmony_ci 63cb7eb8c9Sopenharmony_civoid NativeTokenGet(bool isSystem) 64cb7eb8c9Sopenharmony_ci{ 65cb7eb8c9Sopenharmony_ci uint64_t tokenId; 66cb7eb8c9Sopenharmony_ci static const char *perms[] = {"ohos.permission.CLOUDFILE_SYNC", "ohos.permission.CLOUDFILE_SYNC_MANAGER", 67cb7eb8c9Sopenharmony_ci "ohos.permission.PROXY_AUTHORIZATION_URI"}; 68cb7eb8c9Sopenharmony_ci NativeTokenInfoParams infoInstance = { 69cb7eb8c9Sopenharmony_ci .dcapsNum = 0, 70cb7eb8c9Sopenharmony_ci .permsNum = 3, 71cb7eb8c9Sopenharmony_ci .aclsNum = 0, 72cb7eb8c9Sopenharmony_ci .dcaps = nullptr, 73cb7eb8c9Sopenharmony_ci .perms = perms, 74cb7eb8c9Sopenharmony_ci .acls = nullptr, 75cb7eb8c9Sopenharmony_ci .aplStr = "system_core", 76cb7eb8c9Sopenharmony_ci }; 77cb7eb8c9Sopenharmony_ci 78cb7eb8c9Sopenharmony_ci infoInstance.processName = "CloudOnRemoteRequestFuzzerTest"; 79cb7eb8c9Sopenharmony_ci tokenId = GetAccessTokenId(&infoInstance); 80cb7eb8c9Sopenharmony_ci if (isSystem) { 81cb7eb8c9Sopenharmony_ci const uint64_t systemAppMask = (static_cast<uint64_t>(1) << 32); 82cb7eb8c9Sopenharmony_ci tokenId |= systemAppMask; 83cb7eb8c9Sopenharmony_ci } 84cb7eb8c9Sopenharmony_ci SetSelfTokenID(tokenId); 85cb7eb8c9Sopenharmony_ci OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); 86cb7eb8c9Sopenharmony_ci} 87cb7eb8c9Sopenharmony_ci 88cb7eb8c9Sopenharmony_cibool WriteInterfaceToken(MessageParcel &data) 89cb7eb8c9Sopenharmony_ci{ 90cb7eb8c9Sopenharmony_ci if (!data.WriteInterfaceToken(CLOUD_SYNC_SERVICE_TOKEN)) { 91cb7eb8c9Sopenharmony_ci LOGE("Write token failed."); 92cb7eb8c9Sopenharmony_ci return false; 93cb7eb8c9Sopenharmony_ci } 94cb7eb8c9Sopenharmony_ci return true; 95cb7eb8c9Sopenharmony_ci} 96cb7eb8c9Sopenharmony_ci 97cb7eb8c9Sopenharmony_civoid HandleChangeAppSwitchFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 98cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 99cb7eb8c9Sopenharmony_ci size_t size) 100cb7eb8c9Sopenharmony_ci{ 101cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 102cb7eb8c9Sopenharmony_ci MessageParcel datas; 103cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 104cb7eb8c9Sopenharmony_ci return; 105cb7eb8c9Sopenharmony_ci } 106cb7eb8c9Sopenharmony_ci bool status = fuzzData.GetData<bool>(); 107cb7eb8c9Sopenharmony_ci int pos = static_cast<int>((size - BOOL_AT_SIZE) >> 1); 108cb7eb8c9Sopenharmony_ci std::string accountId = fuzzData.GetStringFromData(pos); 109cb7eb8c9Sopenharmony_ci std::string bundleName = fuzzData.GetStringFromData(pos); 110cb7eb8c9Sopenharmony_ci datas.WriteString(accountId); 111cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 112cb7eb8c9Sopenharmony_ci datas.WriteBool(status); 113cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 114cb7eb8c9Sopenharmony_ci // SERVICE_CMD_CHANGE_APP_SWITCH 115cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CHANGE_APP_SWITCH); 116cb7eb8c9Sopenharmony_ci MessageParcel reply; 117cb7eb8c9Sopenharmony_ci MessageOption option; 118cb7eb8c9Sopenharmony_ci 119cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 120cb7eb8c9Sopenharmony_ci} 121cb7eb8c9Sopenharmony_ci 122cb7eb8c9Sopenharmony_civoid HandleCleanFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, FuzzData &fuzzData, size_t size) 123cb7eb8c9Sopenharmony_ci{ 124cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 125cb7eb8c9Sopenharmony_ci MessageParcel datas; 126cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 127cb7eb8c9Sopenharmony_ci return; 128cb7eb8c9Sopenharmony_ci } 129cb7eb8c9Sopenharmony_ci std::string uri = fuzzData.GetStringFromData(static_cast<int>(size)); 130cb7eb8c9Sopenharmony_ci datas.WriteString(uri); 131cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 132cb7eb8c9Sopenharmony_ci // SERVICE_CMD_CLEAN 133cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CLEAN); 134cb7eb8c9Sopenharmony_ci MessageParcel reply; 135cb7eb8c9Sopenharmony_ci MessageOption option; 136cb7eb8c9Sopenharmony_ci 137cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 138cb7eb8c9Sopenharmony_ci} 139cb7eb8c9Sopenharmony_ci 140cb7eb8c9Sopenharmony_civoid HandleDeleteAssetFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 141cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 142cb7eb8c9Sopenharmony_ci size_t size) 143cb7eb8c9Sopenharmony_ci{ 144cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 145cb7eb8c9Sopenharmony_ci MessageParcel datas; 146cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 147cb7eb8c9Sopenharmony_ci return; 148cb7eb8c9Sopenharmony_ci } 149cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 150cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 151cb7eb8c9Sopenharmony_ci int len = static_cast<int>(size - U32_AT_SIZE); 152cb7eb8c9Sopenharmony_ci std::string uri = fuzzData.GetStringFromData(len); 153cb7eb8c9Sopenharmony_ci datas.WriteString(uri); 154cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 155cb7eb8c9Sopenharmony_ci // SERVICE_CMD_DELETE_ASSET 156cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DELETE_ASSET); 157cb7eb8c9Sopenharmony_ci MessageParcel reply; 158cb7eb8c9Sopenharmony_ci MessageOption option; 159cb7eb8c9Sopenharmony_ci 160cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 161cb7eb8c9Sopenharmony_ci} 162cb7eb8c9Sopenharmony_ci 163cb7eb8c9Sopenharmony_civoid HandleDisableCloudFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 164cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 165cb7eb8c9Sopenharmony_ci size_t size) 166cb7eb8c9Sopenharmony_ci{ 167cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 168cb7eb8c9Sopenharmony_ci MessageParcel datas; 169cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 170cb7eb8c9Sopenharmony_ci return; 171cb7eb8c9Sopenharmony_ci } 172cb7eb8c9Sopenharmony_ci string accountId = fuzzData.GetStringFromData(static_cast<int>(size)); 173cb7eb8c9Sopenharmony_ci datas.WriteString(accountId); 174cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 175cb7eb8c9Sopenharmony_ci // SERVICE_CMD_DISABLE_CLOUD 176cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DISABLE_CLOUD); 177cb7eb8c9Sopenharmony_ci MessageParcel reply; 178cb7eb8c9Sopenharmony_ci MessageOption option; 179cb7eb8c9Sopenharmony_ci 180cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 181cb7eb8c9Sopenharmony_ci} 182cb7eb8c9Sopenharmony_ci 183cb7eb8c9Sopenharmony_civoid HandleDownloadFileFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 184cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 185cb7eb8c9Sopenharmony_ci size_t size) 186cb7eb8c9Sopenharmony_ci{ 187cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 188cb7eb8c9Sopenharmony_ci MessageParcel datas; 189cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 190cb7eb8c9Sopenharmony_ci return; 191cb7eb8c9Sopenharmony_ci } 192cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 193cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 194cb7eb8c9Sopenharmony_ci int pos = static_cast<int>(size - U32_AT_SIZE) / (SPLITE_SIZE + 1); 195cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(pos); 196cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 197cb7eb8c9Sopenharmony_ci AssetInfo assetInfo = {.uri = fuzzData.GetStringFromData(pos), 198cb7eb8c9Sopenharmony_ci .recordType = fuzzData.GetStringFromData(pos), 199cb7eb8c9Sopenharmony_ci .recordId = fuzzData.GetStringFromData(pos), 200cb7eb8c9Sopenharmony_ci .fieldKey = fuzzData.GetStringFromData(pos), 201cb7eb8c9Sopenharmony_ci .assetName = fuzzData.GetStringFromData(pos)}; 202cb7eb8c9Sopenharmony_ci AssetInfoObj assetInfoObj(assetInfo); 203cb7eb8c9Sopenharmony_ci datas.WriteParcelable(&assetInfoObj); 204cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 205cb7eb8c9Sopenharmony_ci // SERVICE_CMD_DOWNLOAD_FILE 206cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DOWNLOAD_FILE); 207cb7eb8c9Sopenharmony_ci MessageParcel reply; 208cb7eb8c9Sopenharmony_ci MessageOption option; 209cb7eb8c9Sopenharmony_ci 210cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 211cb7eb8c9Sopenharmony_ci} 212cb7eb8c9Sopenharmony_ci 213cb7eb8c9Sopenharmony_civoid HandleEnableCloudFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 214cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 215cb7eb8c9Sopenharmony_ci size_t size) 216cb7eb8c9Sopenharmony_ci{ 217cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 218cb7eb8c9Sopenharmony_ci MessageParcel datas; 219cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 220cb7eb8c9Sopenharmony_ci return; 221cb7eb8c9Sopenharmony_ci } 222cb7eb8c9Sopenharmony_ci int pos = static_cast<int>(size >> 1); 223cb7eb8c9Sopenharmony_ci string accountId = fuzzData.GetStringFromData(pos); 224cb7eb8c9Sopenharmony_ci datas.WriteString(accountId); 225cb7eb8c9Sopenharmony_ci int itemStrLen = pos / SPLITE_SIZE; 226cb7eb8c9Sopenharmony_ci if (itemStrLen <= static_cast<int>(BOOL_AT_SIZE)) { 227cb7eb8c9Sopenharmony_ci return; 228cb7eb8c9Sopenharmony_ci } 229cb7eb8c9Sopenharmony_ci std::map<string, bool> switchData; 230cb7eb8c9Sopenharmony_ci for (int i = 0; i < SPLITE_SIZE; i++) { 231cb7eb8c9Sopenharmony_ci string itemStr = fuzzData.GetStringFromData(itemStrLen - static_cast<int>(BOOL_AT_SIZE)); 232cb7eb8c9Sopenharmony_ci bool itemBool = fuzzData.GetData<bool>(); 233cb7eb8c9Sopenharmony_ci switchData.insert(pair<string, bool>(itemStr, itemBool)); 234cb7eb8c9Sopenharmony_ci } 235cb7eb8c9Sopenharmony_ci SwitchDataObj switchDataObj; 236cb7eb8c9Sopenharmony_ci switchDataObj.switchData = switchData; 237cb7eb8c9Sopenharmony_ci datas.WriteParcelable(&switchDataObj); 238cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 239cb7eb8c9Sopenharmony_ci // SERVICE_CMD_ENABLE_CLOUD 240cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_ENABLE_CLOUD); 241cb7eb8c9Sopenharmony_ci MessageParcel reply; 242cb7eb8c9Sopenharmony_ci MessageOption option; 243cb7eb8c9Sopenharmony_ci 244cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 245cb7eb8c9Sopenharmony_ci} 246cb7eb8c9Sopenharmony_ci 247cb7eb8c9Sopenharmony_civoid HandleNotifyDataChangeFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 248cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 249cb7eb8c9Sopenharmony_ci size_t size) 250cb7eb8c9Sopenharmony_ci{ 251cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 252cb7eb8c9Sopenharmony_ci MessageParcel datas; 253cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 254cb7eb8c9Sopenharmony_ci return; 255cb7eb8c9Sopenharmony_ci } 256cb7eb8c9Sopenharmony_ci int pos = static_cast<int>(size >> 1); 257cb7eb8c9Sopenharmony_ci string accountId = fuzzData.GetStringFromData(pos); 258cb7eb8c9Sopenharmony_ci datas.WriteString(accountId); 259cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(pos); 260cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 261cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 262cb7eb8c9Sopenharmony_ci // SERVICE_CMD_NOTIFY_DATA_CHANGE 263cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_NOTIFY_DATA_CHANGE); 264cb7eb8c9Sopenharmony_ci MessageParcel reply; 265cb7eb8c9Sopenharmony_ci MessageOption option; 266cb7eb8c9Sopenharmony_ci 267cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 268cb7eb8c9Sopenharmony_ci} 269cb7eb8c9Sopenharmony_ci 270cb7eb8c9Sopenharmony_civoid HandleRegisterCallbackInnerFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 271cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 272cb7eb8c9Sopenharmony_ci size_t size) 273cb7eb8c9Sopenharmony_ci{ 274cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 275cb7eb8c9Sopenharmony_ci MessageParcel datas; 276cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 277cb7eb8c9Sopenharmony_ci return; 278cb7eb8c9Sopenharmony_ci } 279cb7eb8c9Sopenharmony_ci sptr<ICloudSyncCallbackTest> callback = new (std::nothrow) ICloudSyncCallbackTest(); 280cb7eb8c9Sopenharmony_ci if (callback == nullptr) { 281cb7eb8c9Sopenharmony_ci return; 282cb7eb8c9Sopenharmony_ci } 283cb7eb8c9Sopenharmony_ci datas.WriteRemoteObject(callback->AsObject().GetRefPtr()); 284cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(static_cast<int>(size)); 285cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 286cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 287cb7eb8c9Sopenharmony_ci // SERVICE_CMD_REGISTER_CALLBACK 288cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_CALLBACK); 289cb7eb8c9Sopenharmony_ci MessageParcel reply; 290cb7eb8c9Sopenharmony_ci MessageOption option; 291cb7eb8c9Sopenharmony_ci 292cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 293cb7eb8c9Sopenharmony_ci} 294cb7eb8c9Sopenharmony_ci 295cb7eb8c9Sopenharmony_civoid HandleRegisterDownloadFileCallbackFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 296cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 297cb7eb8c9Sopenharmony_ci size_t size) 298cb7eb8c9Sopenharmony_ci{ 299cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 300cb7eb8c9Sopenharmony_ci MessageParcel datas; 301cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 302cb7eb8c9Sopenharmony_ci return; 303cb7eb8c9Sopenharmony_ci } 304cb7eb8c9Sopenharmony_ci sptr<ICloudDownloadCallbackTest> callback = new (std::nothrow) ICloudDownloadCallbackTest(); 305cb7eb8c9Sopenharmony_ci if (callback == nullptr) { 306cb7eb8c9Sopenharmony_ci return; 307cb7eb8c9Sopenharmony_ci } 308cb7eb8c9Sopenharmony_ci datas.WriteRemoteObject(callback->AsObject().GetRefPtr()); 309cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 310cb7eb8c9Sopenharmony_ci // SERVICE_CMD_REGISTER_DOWNLOAD_FILE_CALLBACK 311cb7eb8c9Sopenharmony_ci uint32_t code = 312cb7eb8c9Sopenharmony_ci static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_DOWNLOAD_FILE_CALLBACK); 313cb7eb8c9Sopenharmony_ci MessageParcel reply; 314cb7eb8c9Sopenharmony_ci MessageOption option; 315cb7eb8c9Sopenharmony_ci 316cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 317cb7eb8c9Sopenharmony_ci} 318cb7eb8c9Sopenharmony_ci 319cb7eb8c9Sopenharmony_civoid HandleStartDownloadFileFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 320cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 321cb7eb8c9Sopenharmony_ci size_t size) 322cb7eb8c9Sopenharmony_ci{ 323cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 324cb7eb8c9Sopenharmony_ci MessageParcel datas; 325cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 326cb7eb8c9Sopenharmony_ci return; 327cb7eb8c9Sopenharmony_ci } 328cb7eb8c9Sopenharmony_ci string path = fuzzData.GetStringFromData(static_cast<int>(size)); 329cb7eb8c9Sopenharmony_ci datas.WriteString(path); 330cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 331cb7eb8c9Sopenharmony_ci // SERVICE_CMD_START_DOWNLOAD_FILE 332cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_DOWNLOAD_FILE); 333cb7eb8c9Sopenharmony_ci MessageParcel reply; 334cb7eb8c9Sopenharmony_ci MessageOption option; 335cb7eb8c9Sopenharmony_ci 336cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 337cb7eb8c9Sopenharmony_ci} 338cb7eb8c9Sopenharmony_ci 339cb7eb8c9Sopenharmony_civoid HandleStartSyncInnerFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 340cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 341cb7eb8c9Sopenharmony_ci size_t size) 342cb7eb8c9Sopenharmony_ci{ 343cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 344cb7eb8c9Sopenharmony_ci MessageParcel datas; 345cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 346cb7eb8c9Sopenharmony_ci return; 347cb7eb8c9Sopenharmony_ci } 348cb7eb8c9Sopenharmony_ci auto forceFlag = fuzzData.GetData<bool>(); 349cb7eb8c9Sopenharmony_ci datas.WriteBool(forceFlag); 350cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(static_cast<int>(size - BOOL_AT_SIZE)); 351cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 352cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 353cb7eb8c9Sopenharmony_ci // SERVICE_CMD_START_SYNC 354cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_SYNC); 355cb7eb8c9Sopenharmony_ci MessageParcel reply; 356cb7eb8c9Sopenharmony_ci MessageOption option; 357cb7eb8c9Sopenharmony_ci 358cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 359cb7eb8c9Sopenharmony_ci} 360cb7eb8c9Sopenharmony_ci 361cb7eb8c9Sopenharmony_civoid HandleStopDownloadFileFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 362cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 363cb7eb8c9Sopenharmony_ci size_t size) 364cb7eb8c9Sopenharmony_ci{ 365cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 366cb7eb8c9Sopenharmony_ci MessageParcel datas; 367cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 368cb7eb8c9Sopenharmony_ci return; 369cb7eb8c9Sopenharmony_ci } 370cb7eb8c9Sopenharmony_ci string path = fuzzData.GetStringFromData(static_cast<int>(size)); 371cb7eb8c9Sopenharmony_ci datas.WriteString(path); 372cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 373cb7eb8c9Sopenharmony_ci // SERVICE_CMD_STOP_DOWNLOAD_FILE 374cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_STOP_DOWNLOAD_FILE); 375cb7eb8c9Sopenharmony_ci MessageParcel reply; 376cb7eb8c9Sopenharmony_ci MessageOption option; 377cb7eb8c9Sopenharmony_ci 378cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 379cb7eb8c9Sopenharmony_ci} 380cb7eb8c9Sopenharmony_ci 381cb7eb8c9Sopenharmony_civoid HandleStopSyncInnerFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 382cb7eb8c9Sopenharmony_ci const uint8_t *data, 383cb7eb8c9Sopenharmony_ci size_t size) 384cb7eb8c9Sopenharmony_ci{ 385cb7eb8c9Sopenharmony_ci MessageParcel datas; 386cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 387cb7eb8c9Sopenharmony_ci return; 388cb7eb8c9Sopenharmony_ci } 389cb7eb8c9Sopenharmony_ci datas.WriteBuffer(data, size); 390cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 391cb7eb8c9Sopenharmony_ci // SERVICE_CMD_STOP_SYNC 392cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_STOP_SYNC); 393cb7eb8c9Sopenharmony_ci MessageParcel reply; 394cb7eb8c9Sopenharmony_ci MessageOption option; 395cb7eb8c9Sopenharmony_ci 396cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 397cb7eb8c9Sopenharmony_ci} 398cb7eb8c9Sopenharmony_ci 399cb7eb8c9Sopenharmony_civoid HandleUnRegisterCallbackInnerFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 400cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 401cb7eb8c9Sopenharmony_ci size_t size) 402cb7eb8c9Sopenharmony_ci{ 403cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 404cb7eb8c9Sopenharmony_ci MessageParcel datas; 405cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 406cb7eb8c9Sopenharmony_ci return; 407cb7eb8c9Sopenharmony_ci } 408cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(static_cast<int>(size)); 409cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 410cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 411cb7eb8c9Sopenharmony_ci // SERVICE_CMD_UNREGISTER_CALLBACK 412cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UNREGISTER_CALLBACK); 413cb7eb8c9Sopenharmony_ci MessageParcel reply; 414cb7eb8c9Sopenharmony_ci MessageOption option; 415cb7eb8c9Sopenharmony_ci 416cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 417cb7eb8c9Sopenharmony_ci} 418cb7eb8c9Sopenharmony_ci 419cb7eb8c9Sopenharmony_civoid HandleUnRegisterDownloadFileCallbackFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 420cb7eb8c9Sopenharmony_ci const uint8_t *data, 421cb7eb8c9Sopenharmony_ci size_t size) 422cb7eb8c9Sopenharmony_ci{ 423cb7eb8c9Sopenharmony_ci MessageParcel datas; 424cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 425cb7eb8c9Sopenharmony_ci return; 426cb7eb8c9Sopenharmony_ci } 427cb7eb8c9Sopenharmony_ci datas.WriteBuffer(data, size); 428cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 429cb7eb8c9Sopenharmony_ci // SERVICE_CMD_UNREGISTER_DOWNLOAD_FILE_CALLBACK 430cb7eb8c9Sopenharmony_ci uint32_t code = 431cb7eb8c9Sopenharmony_ci static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UNREGISTER_DOWNLOAD_FILE_CALLBACK); 432cb7eb8c9Sopenharmony_ci MessageParcel reply; 433cb7eb8c9Sopenharmony_ci MessageOption option; 434cb7eb8c9Sopenharmony_ci 435cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 436cb7eb8c9Sopenharmony_ci} 437cb7eb8c9Sopenharmony_ci 438cb7eb8c9Sopenharmony_civoid HandleUploadAssetFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 439cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 440cb7eb8c9Sopenharmony_ci size_t size) 441cb7eb8c9Sopenharmony_ci{ 442cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 443cb7eb8c9Sopenharmony_ci MessageParcel datas; 444cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 445cb7eb8c9Sopenharmony_ci return; 446cb7eb8c9Sopenharmony_ci } 447cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 448cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 449cb7eb8c9Sopenharmony_ci int len = static_cast<int32_t>(size - U32_AT_SIZE); 450cb7eb8c9Sopenharmony_ci string request = fuzzData.GetStringFromData(len); 451cb7eb8c9Sopenharmony_ci datas.WriteString(request); 452cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 453cb7eb8c9Sopenharmony_ci // SERVICE_CMD_UPLOAD_ASSET 454cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_UPLOAD_ASSET); 455cb7eb8c9Sopenharmony_ci MessageParcel reply; 456cb7eb8c9Sopenharmony_ci MessageOption option; 457cb7eb8c9Sopenharmony_ci 458cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 459cb7eb8c9Sopenharmony_ci} 460cb7eb8c9Sopenharmony_ci 461cb7eb8c9Sopenharmony_civoid HandleTriggerSyncInnerFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 462cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 463cb7eb8c9Sopenharmony_ci size_t size) 464cb7eb8c9Sopenharmony_ci{ 465cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 466cb7eb8c9Sopenharmony_ci MessageParcel datas; 467cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 468cb7eb8c9Sopenharmony_ci return; 469cb7eb8c9Sopenharmony_ci } 470cb7eb8c9Sopenharmony_ci int len = static_cast<int32_t>(size - U32_AT_SIZE); 471cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(len); 472cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 473cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 474cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 475cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 476cb7eb8c9Sopenharmony_ci // SERVICE_CMD_TRIGGER_SYNC 477cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_TRIGGER_SYNC); 478cb7eb8c9Sopenharmony_ci MessageParcel reply; 479cb7eb8c9Sopenharmony_ci MessageOption option; 480cb7eb8c9Sopenharmony_ci 481cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 482cb7eb8c9Sopenharmony_ci} 483cb7eb8c9Sopenharmony_ci 484cb7eb8c9Sopenharmony_civoid HandleNotifyEventChangeFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 485cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 486cb7eb8c9Sopenharmony_ci size_t size) 487cb7eb8c9Sopenharmony_ci{ 488cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 489cb7eb8c9Sopenharmony_ci MessageParcel datas; 490cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 491cb7eb8c9Sopenharmony_ci return; 492cb7eb8c9Sopenharmony_ci } 493cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 494cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 495cb7eb8c9Sopenharmony_ci 496cb7eb8c9Sopenharmony_ci int pos = static_cast<int>((size - U32_AT_SIZE) >> 1); 497cb7eb8c9Sopenharmony_ci string eventIdStr = fuzzData.GetStringFromData(pos); 498cb7eb8c9Sopenharmony_ci string extraDataStr = fuzzData.GetStringFromData(pos); 499cb7eb8c9Sopenharmony_ci datas.WriteString(eventIdStr); 500cb7eb8c9Sopenharmony_ci datas.WriteString(extraDataStr); 501cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 502cb7eb8c9Sopenharmony_ci // SERVICE_CMD_NOTIFY_EVENT_CHANGE 503cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_NOTIFY_EVENT_CHANGE); 504cb7eb8c9Sopenharmony_ci MessageParcel reply; 505cb7eb8c9Sopenharmony_ci MessageOption option; 506cb7eb8c9Sopenharmony_ci 507cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 508cb7eb8c9Sopenharmony_ci} 509cb7eb8c9Sopenharmony_ci 510cb7eb8c9Sopenharmony_civoid HandleStartFileCacheFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 511cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 512cb7eb8c9Sopenharmony_ci size_t size) 513cb7eb8c9Sopenharmony_ci{ 514cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 515cb7eb8c9Sopenharmony_ci MessageParcel datas; 516cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 517cb7eb8c9Sopenharmony_ci return; 518cb7eb8c9Sopenharmony_ci } 519cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 520cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 521cb7eb8c9Sopenharmony_ci int pos = static_cast<int>((size - U32_AT_SIZE) >> 1); 522cb7eb8c9Sopenharmony_ci string eventIdStr = fuzzData.GetStringFromData(pos); 523cb7eb8c9Sopenharmony_ci string extraDataStr = fuzzData.GetStringFromData(pos); 524cb7eb8c9Sopenharmony_ci datas.WriteString(eventIdStr); 525cb7eb8c9Sopenharmony_ci datas.WriteString(extraDataStr); 526cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 527cb7eb8c9Sopenharmony_ci // SERVICE_CMD_START_FILE_CACHE 528cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_START_FILE_CACHE); 529cb7eb8c9Sopenharmony_ci MessageParcel reply; 530cb7eb8c9Sopenharmony_ci MessageOption option; 531cb7eb8c9Sopenharmony_ci 532cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 533cb7eb8c9Sopenharmony_ci} 534cb7eb8c9Sopenharmony_ci 535cb7eb8c9Sopenharmony_civoid HandleDownloadFilesFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 536cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 537cb7eb8c9Sopenharmony_ci size_t size) 538cb7eb8c9Sopenharmony_ci{ 539cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 540cb7eb8c9Sopenharmony_ci MessageParcel datas; 541cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 542cb7eb8c9Sopenharmony_ci return; 543cb7eb8c9Sopenharmony_ci } 544cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 545cb7eb8c9Sopenharmony_ci datas.WriteInt32(userId); 546cb7eb8c9Sopenharmony_ci int32_t vecSize = fuzzData.GetData<int32_t>() % SPLITE_SIZE + 1; 547cb7eb8c9Sopenharmony_ci auto remainSize = fuzzData.GetRemainSize(); 548cb7eb8c9Sopenharmony_ci if (static_cast<int>(remainSize) <= vecSize * SPLITE_SIZE + 1) { 549cb7eb8c9Sopenharmony_ci return; 550cb7eb8c9Sopenharmony_ci } 551cb7eb8c9Sopenharmony_ci int len = static_cast<int>(remainSize / (vecSize * SPLITE_SIZE + 1)); 552cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(len); 553cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 554cb7eb8c9Sopenharmony_ci datas.WriteInt32(vecSize); 555cb7eb8c9Sopenharmony_ci for (auto i = 0; i < vecSize; i++) { 556cb7eb8c9Sopenharmony_ci AssetInfo assetInfo = {.uri = fuzzData.GetStringFromData(len), 557cb7eb8c9Sopenharmony_ci .recordType = fuzzData.GetStringFromData(len), 558cb7eb8c9Sopenharmony_ci .recordId = fuzzData.GetStringFromData(len), 559cb7eb8c9Sopenharmony_ci .fieldKey = fuzzData.GetStringFromData(len), 560cb7eb8c9Sopenharmony_ci .assetName = fuzzData.GetStringFromData(len)}; 561cb7eb8c9Sopenharmony_ci AssetInfoObj assetInfoObj(assetInfo); 562cb7eb8c9Sopenharmony_ci datas.WriteParcelable(&assetInfoObj); 563cb7eb8c9Sopenharmony_ci } 564cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 565cb7eb8c9Sopenharmony_ci // SERVICE_CMD_DOWNLOAD_FILES 566cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DOWNLOAD_FILES); 567cb7eb8c9Sopenharmony_ci MessageParcel reply; 568cb7eb8c9Sopenharmony_ci MessageOption option; 569cb7eb8c9Sopenharmony_ci 570cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 571cb7eb8c9Sopenharmony_ci} 572cb7eb8c9Sopenharmony_ci 573cb7eb8c9Sopenharmony_civoid HandleDownloadAssetFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 574cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 575cb7eb8c9Sopenharmony_ci size_t size) 576cb7eb8c9Sopenharmony_ci{ 577cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 578cb7eb8c9Sopenharmony_ci MessageParcel datas; 579cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 580cb7eb8c9Sopenharmony_ci return; 581cb7eb8c9Sopenharmony_ci } 582cb7eb8c9Sopenharmony_ci uint64_t taskId = fuzzData.GetData<uint64_t>(); 583cb7eb8c9Sopenharmony_ci datas.WriteUint64(taskId); 584cb7eb8c9Sopenharmony_ci int32_t userId = fuzzData.GetData<int32_t>(); 585cb7eb8c9Sopenharmony_ci datas.WriteUint32(userId); 586cb7eb8c9Sopenharmony_ci int len = static_cast<int>(fuzzData.GetRemainSize() >> 1); 587cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(len); 588cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 589cb7eb8c9Sopenharmony_ci string networkId = fuzzData.GetStringFromData(len); 590cb7eb8c9Sopenharmony_ci datas.WriteString(networkId); 591cb7eb8c9Sopenharmony_ci 592cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 593cb7eb8c9Sopenharmony_ci len = static_cast<int>(size) / SPLITE_SIZE; 594cb7eb8c9Sopenharmony_ci AssetInfo assetInfo = {.uri = fuzzData.GetStringFromData(len), 595cb7eb8c9Sopenharmony_ci .recordType = fuzzData.GetStringFromData(len), 596cb7eb8c9Sopenharmony_ci .recordId = fuzzData.GetStringFromData(len), 597cb7eb8c9Sopenharmony_ci .fieldKey = fuzzData.GetStringFromData(len), 598cb7eb8c9Sopenharmony_ci .assetName = fuzzData.GetStringFromData(len)}; 599cb7eb8c9Sopenharmony_ci AssetInfoObj assetInfoObj(assetInfo); 600cb7eb8c9Sopenharmony_ci datas.WriteParcelable(&assetInfoObj); 601cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 602cb7eb8c9Sopenharmony_ci // SERVICE_CMD_DOWNLOAD_ASSET 603cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_DOWNLOAD_ASSET); 604cb7eb8c9Sopenharmony_ci MessageParcel reply; 605cb7eb8c9Sopenharmony_ci MessageOption option; 606cb7eb8c9Sopenharmony_ci 607cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 608cb7eb8c9Sopenharmony_ci} 609cb7eb8c9Sopenharmony_ci 610cb7eb8c9Sopenharmony_civoid HandleRegisterDownloadAssetCallbackFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 611cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 612cb7eb8c9Sopenharmony_ci size_t size) 613cb7eb8c9Sopenharmony_ci{ 614cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 615cb7eb8c9Sopenharmony_ci MessageParcel datas; 616cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 617cb7eb8c9Sopenharmony_ci return; 618cb7eb8c9Sopenharmony_ci } 619cb7eb8c9Sopenharmony_ci sptr<IDownloadAssetCallbackTest> callback = new (std::nothrow) IDownloadAssetCallbackTest(); 620cb7eb8c9Sopenharmony_ci if (callback == nullptr) { 621cb7eb8c9Sopenharmony_ci return; 622cb7eb8c9Sopenharmony_ci } 623cb7eb8c9Sopenharmony_ci datas.WriteRemoteObject(callback->AsObject().GetRefPtr()); 624cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 625cb7eb8c9Sopenharmony_ci // SERVICE_CMD_REGISTER_DOWNLOAD_ASSET_CALLBACK 626cb7eb8c9Sopenharmony_ci uint32_t code = 627cb7eb8c9Sopenharmony_ci static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_REGISTER_DOWNLOAD_ASSET_CALLBACK); 628cb7eb8c9Sopenharmony_ci MessageParcel reply; 629cb7eb8c9Sopenharmony_ci MessageOption option; 630cb7eb8c9Sopenharmony_ci 631cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 632cb7eb8c9Sopenharmony_ci} 633cb7eb8c9Sopenharmony_ci 634cb7eb8c9Sopenharmony_civoid HandleGetSyncTimeFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 635cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 636cb7eb8c9Sopenharmony_ci size_t size) 637cb7eb8c9Sopenharmony_ci{ 638cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 639cb7eb8c9Sopenharmony_ci MessageParcel datas; 640cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 641cb7eb8c9Sopenharmony_ci return; 642cb7eb8c9Sopenharmony_ci } 643cb7eb8c9Sopenharmony_ci string bundleName = fuzzData.GetStringFromData(static_cast<int>(size)); 644cb7eb8c9Sopenharmony_ci datas.WriteString(bundleName); 645cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 646cb7eb8c9Sopenharmony_ci // SERVICE_CMD_GET_SYNC_TIME 647cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_GET_SYNC_TIME); 648cb7eb8c9Sopenharmony_ci MessageParcel reply; 649cb7eb8c9Sopenharmony_ci MessageOption option; 650cb7eb8c9Sopenharmony_ci 651cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 652cb7eb8c9Sopenharmony_ci} 653cb7eb8c9Sopenharmony_ci 654cb7eb8c9Sopenharmony_civoid HandleCleanCacheFuzzTest(std::shared_ptr<CloudSyncServiceStub> cloudSyncServiceStubStr, 655cb7eb8c9Sopenharmony_ci FuzzData &fuzzData, 656cb7eb8c9Sopenharmony_ci size_t size) 657cb7eb8c9Sopenharmony_ci{ 658cb7eb8c9Sopenharmony_ci fuzzData.ResetData(size); 659cb7eb8c9Sopenharmony_ci MessageParcel datas; 660cb7eb8c9Sopenharmony_ci if (!WriteInterfaceToken(datas)) { 661cb7eb8c9Sopenharmony_ci return; 662cb7eb8c9Sopenharmony_ci } 663cb7eb8c9Sopenharmony_ci string uri = fuzzData.GetStringFromData(static_cast<int>(size)); 664cb7eb8c9Sopenharmony_ci datas.WriteString(uri); 665cb7eb8c9Sopenharmony_ci datas.RewindRead(0); 666cb7eb8c9Sopenharmony_ci // SERVICE_CMD_CLEAN_CACHE 667cb7eb8c9Sopenharmony_ci uint32_t code = static_cast<uint32_t>(CloudFileSyncServiceInterfaceCode::SERVICE_CMD_CLEAN_CACHE); 668cb7eb8c9Sopenharmony_ci MessageParcel reply; 669cb7eb8c9Sopenharmony_ci MessageOption option; 670cb7eb8c9Sopenharmony_ci 671cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->OnRemoteRequest(code, datas, reply, option); 672cb7eb8c9Sopenharmony_ci} 673cb7eb8c9Sopenharmony_ci} // namespace OHOS 674cb7eb8c9Sopenharmony_ci 675cb7eb8c9Sopenharmony_ci/* Fuzzer entry point */ 676cb7eb8c9Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 677cb7eb8c9Sopenharmony_ci{ 678cb7eb8c9Sopenharmony_ci /* Run your code on data */ 679cb7eb8c9Sopenharmony_ci if (data == nullptr || size < OHOS::U32_AT_SIZE * static_cast<size_t>(OHOS::SPLITE_SIZE)) { 680cb7eb8c9Sopenharmony_ci return 0; 681cb7eb8c9Sopenharmony_ci } 682cb7eb8c9Sopenharmony_ci 683cb7eb8c9Sopenharmony_ci OHOS::NativeTokenGet(true); 684cb7eb8c9Sopenharmony_ci auto cloudSyncServiceStubStr = 685cb7eb8c9Sopenharmony_ci std::make_shared<OHOS::FileManagement::CloudSync::CloudSyncService>(OHOS::SERVICE_SA_ID); 686cb7eb8c9Sopenharmony_ci if (cloudSyncServiceStubStr->dataSyncManager_ == nullptr) { 687cb7eb8c9Sopenharmony_ci cloudSyncServiceStubStr->dataSyncManager_ = 688cb7eb8c9Sopenharmony_ci std::make_shared<OHOS::FileManagement::CloudFile::DataSyncManager>(); 689cb7eb8c9Sopenharmony_ci } 690cb7eb8c9Sopenharmony_ci 691cb7eb8c9Sopenharmony_ci OHOS::FuzzData fuzzData(data, size); 692cb7eb8c9Sopenharmony_ci OHOS::HandleChangeAppSwitchFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 693cb7eb8c9Sopenharmony_ci OHOS::HandleCleanFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 694cb7eb8c9Sopenharmony_ci OHOS::HandleDeleteAssetFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 695cb7eb8c9Sopenharmony_ci OHOS::HandleDisableCloudFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 696cb7eb8c9Sopenharmony_ci OHOS::HandleDownloadFileFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 697cb7eb8c9Sopenharmony_ci OHOS::HandleEnableCloudFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 698cb7eb8c9Sopenharmony_ci OHOS::HandleNotifyDataChangeFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 699cb7eb8c9Sopenharmony_ci OHOS::HandleRegisterCallbackInnerFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 700cb7eb8c9Sopenharmony_ci OHOS::HandleRegisterDownloadFileCallbackFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 701cb7eb8c9Sopenharmony_ci OHOS::HandleStartDownloadFileFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 702cb7eb8c9Sopenharmony_ci OHOS::HandleStartSyncInnerFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 703cb7eb8c9Sopenharmony_ci OHOS::HandleStopDownloadFileFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 704cb7eb8c9Sopenharmony_ci OHOS::HandleStopSyncInnerFuzzTest(cloudSyncServiceStubStr, data, size); 705cb7eb8c9Sopenharmony_ci OHOS::HandleUnRegisterCallbackInnerFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 706cb7eb8c9Sopenharmony_ci OHOS::HandleUnRegisterDownloadFileCallbackFuzzTest(cloudSyncServiceStubStr, data, size); 707cb7eb8c9Sopenharmony_ci OHOS::HandleUploadAssetFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 708cb7eb8c9Sopenharmony_ci OHOS::HandleTriggerSyncInnerFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 709cb7eb8c9Sopenharmony_ci OHOS::HandleNotifyEventChangeFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 710cb7eb8c9Sopenharmony_ci OHOS::HandleStartFileCacheFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 711cb7eb8c9Sopenharmony_ci OHOS::HandleDownloadFilesFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 712cb7eb8c9Sopenharmony_ci OHOS::HandleDownloadAssetFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 713cb7eb8c9Sopenharmony_ci OHOS::HandleRegisterDownloadAssetCallbackFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 714cb7eb8c9Sopenharmony_ci OHOS::HandleGetSyncTimeFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 715cb7eb8c9Sopenharmony_ci OHOS::HandleCleanCacheFuzzTest(cloudSyncServiceStubStr, fuzzData, size); 716cb7eb8c9Sopenharmony_ci if (OHOS::FileManagement::CloudSync::TaskStateManager::GetInstance().unloadTaskHandle_ != nullptr) { 717cb7eb8c9Sopenharmony_ci OHOS::FileManagement::CloudSync::TaskStateManager::GetInstance().queue_.wait( 718cb7eb8c9Sopenharmony_ci OHOS::FileManagement::CloudSync::TaskStateManager::GetInstance().unloadTaskHandle_); 719cb7eb8c9Sopenharmony_ci } 720cb7eb8c9Sopenharmony_ci return 0; 721cb7eb8c9Sopenharmony_ci} 722