diff --git a/download/dfx/dump/dump_service_impl.cpp b/download/dfx/dump/dump_service_impl.cpp index 1a29846..fe4d0f4 100644 --- a/download/dfx/dump/dump_service_impl.cpp +++ b/download/dfx/dump/dump_service_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,7 +13,6 @@ * limitations under the License. */ - #include #include #include @@ -44,7 +43,7 @@ DumpServiceImpl &DumpServiceImpl::GetInstance() return instance; } -DumperType DumpServiceImpl::GetDumperType(const std::string &cmd) +DumperType DumpServiceImpl::GetDumperType(const std::string &cmd) const { if (cmd == "-h") { return HELP_DUMPER; @@ -68,7 +67,7 @@ int DumpServiceImpl::Dump(int fd, const std::vector &args) return 0; } - DumperFactoryMap::iterator it = dumperFactoryMap_.find(dumperType); + DumperFactoryMap::const_iterator it = dumperFactoryMap_.find(dumperType); if (it == dumperFactoryMap_.end()) { dprintf(fd, "invalid arg\n"); return 0; @@ -82,7 +81,7 @@ int DumpServiceImpl::Dump(int fd, const std::vector &args) return 0; } -void DumpServiceImpl::DumpHelp(int fd) +void DumpServiceImpl::DumpHelp(int fd) const { constexpr const char *DEFAULT_HELPER = "usage:\n" diff --git a/download/dfx/dump/dump_service_impl.h b/download/dfx/dump/dump_service_impl.h index c9705ef..232187c 100644 --- a/download/dfx/dump/dump_service_impl.h +++ b/download/dfx/dump/dump_service_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -39,8 +39,8 @@ private: DumpServiceImpl &operator=(DumpServiceImpl &&) = delete; void InitDumperFactoryMap(); - void DumpHelp(int fd); - DumperType GetDumperType(const std::string &cmd); + void DumpHelp(int fd) const; + DumperType GetDumperType(const std::string &cmd) const; private: using DumperFactoryMap = std::map>; DumperFactoryMap dumperFactoryMap_; diff --git a/download/dfx/dump/dump_task_info.cpp b/download/dfx/dump/dump_task_info.cpp index bb3b4b8..544e32a 100644 --- a/download/dfx/dump/dump_task_info.cpp +++ b/download/dfx/dump/dump_task_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,7 +20,7 @@ namespace OHOS::Request::Download { bool DumpTaskInfo::Dump(int fd, const std::vector &args) { - int32_t argsNum = args.size(); + uint32_t argsNum = args.size(); if (argsNum > 1) { dprintf(fd, "too many args, -t accept no arg or one arg \n"); return false; @@ -35,7 +35,7 @@ bool DumpTaskInfo::Dump(int fd, const std::vector &args) return true; } -void DumpTaskInfo::DumpAllTaskTile(int fd) +void DumpTaskInfo::DumpAllTaskTile(int fd) const { std::ostringstream buffer; buffer << std::left; @@ -43,21 +43,21 @@ void DumpTaskInfo::DumpAllTaskTile(int fd) dprintf(fd, "%s\n", buffer.str().c_str()); } -void DumpTaskInfo::FormatSummaryTitle(std::ostringstream &buffer) +void DumpTaskInfo::FormatSummaryTitle(std::ostringstream &buffer) const { for (const auto &it: summaryColumnTitle_) { buffer << std::setw(it.first) << it.second; } } -void DumpTaskInfo::FormatDetailTitle(std::ostringstream &buffer) +void DumpTaskInfo::FormatDetailTitle(std::ostringstream &buffer) const { for (const auto &it: detailColumnTitle_) { buffer << std::setw(it.first) << it.second; } } -void DumpTaskInfo::DumpTaskDetailInfoTile(int fd) +void DumpTaskInfo::DumpTaskDetailInfoTile(int fd) const { std::ostringstream buffer; buffer << std::left; @@ -66,7 +66,7 @@ void DumpTaskInfo::DumpTaskDetailInfoTile(int fd) dprintf(fd, "%s\n", buffer.str().c_str()); } -void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) +void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const { for (const auto &it: dumpSummaryCfg_) { auto columnFormatFun = it.second; @@ -74,7 +74,7 @@ void DumpTaskInfo::FormatSummaryContent(const DownloadInfo &taskInfo, std::ostri } } -void DumpTaskInfo::FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) +void DumpTaskInfo::FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const { for (const auto &it: dumpDetailCfg_) { auto columnFormatFun = it.second; @@ -127,7 +127,7 @@ std::string DumpTaskInfo::DumpTaskID(const DownloadInfo &taskInfo) const std::string DumpTaskInfo::DumpTaskType(const DownloadInfo &taskInfo) const { - return "download"; + return taskInfo.GetTaskType(); } std::string DumpTaskInfo::DumpTaskStatus(const DownloadInfo &taskInfo) const diff --git a/download/dfx/dump/dump_task_info.h b/download/dfx/dump/dump_task_info.h index bbc8cbb..65f684e 100644 --- a/download/dfx/dump/dump_task_info.h +++ b/download/dfx/dump/dump_task_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,14 +31,14 @@ public: bool Dump(int fd, const std::vector &args) override; private: - void DumpAllTaskTile(int fd); + void DumpAllTaskTile(int fd) const; bool DumpAllTask(int fd); - void DumpTaskDetailInfoTile(int fd); + void DumpTaskDetailInfoTile(int fd) const; bool DumpTaskDetailInfo(int fd, uint32_t taskId); - void FormatSummaryTitle(std::ostringstream &buffer); - void FormatDetailTitle(std::ostringstream &buffer); - void FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer); - void FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer); + void FormatSummaryTitle(std::ostringstream &buffer) const; + void FormatDetailTitle(std::ostringstream &buffer) const; + void FormatSummaryContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const; + void FormatDetailContent(const DownloadInfo &taskInfo, std::ostringstream &buffer) const; private: std::string DumpTaskID(const DownloadInfo &taskInfo) const; std::string DumpTaskType(const DownloadInfo &taskInfo) const; diff --git a/download/dfx/dump/dumper_factory.h b/download/dfx/dump/dumper_factory.h index 73d42d5..cf004fd 100644 --- a/download/dfx/dump/dumper_factory.h +++ b/download/dfx/dump/dumper_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/dump/i_dumper.h b/download/dfx/dump/i_dumper.h index 9af3e8c..728a102 100644 --- a/download/dfx/dump/i_dumper.h +++ b/download/dfx/dump/i_dumper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/dump/task_info_dumper_factory.cpp b/download/dfx/dump/task_info_dumper_factory.cpp index e294f73..247fdec 100644 --- a/download/dfx/dump/task_info_dumper_factory.cpp +++ b/download/dfx/dump/task_info_dumper_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/dump/task_info_dumper_factory.h b/download/dfx/dump/task_info_dumper_factory.h index 7d921e8..100c527 100644 --- a/download/dfx/dump/task_info_dumper_factory.h +++ b/download/dfx/dump/task_info_dumper_factory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/event/fault/task_fault.cpp b/download/dfx/event/fault/task_fault.cpp index fa83577..5b572d2 100644 --- a/download/dfx/event/fault/task_fault.cpp +++ b/download/dfx/event/fault/task_fault.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/event/fault/task_fault.h b/download/dfx/event/fault/task_fault.h index 8409a4a..f407a3e 100644 --- a/download/dfx/event/fault/task_fault.h +++ b/download/dfx/event/fault/task_fault.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/download/dfx/event/statistics/task_statistics.cpp b/download/dfx/event/statistics/task_statistics.cpp index c5bad1d..f26197b 100644 --- a/download/dfx/event/statistics/task_statistics.cpp +++ b/download/dfx/event/statistics/task_statistics.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,24 +28,22 @@ TaskStatistics &TaskStatistics::GetInstance() void TaskStatistics::ReportTasksSize(uint64_t totalSize) { - std::lock_guard lock(mutex_); - DayTasksSize_ += totalSize; + dayTasksSize_ += totalSize; } void TaskStatistics::ReportTasksNumber() { - std::lock_guard lock(mutex_); - DayTasksNumber_ ++; + dayTasksNumber_ ++; } uint64_t TaskStatistics::GetDayTasksSize() const { - return DayTasksSize_; + return dayTasksSize_; } uint32_t TaskStatistics::GetDayTasksNumber() const { - return DayTasksNumber_; + return dayTasksNumber_; } int32_t TaskStatistics::GetNextReportInterval() const @@ -70,8 +68,8 @@ void TaskStatistics::ReportStatistics() const OHOS::HiviewDFX::HiSysEvent::Write(OHOS::HiviewDFX::HiSysEvent::Domain::REQUEST, REQUEST_TASK_INFO_STATISTICS, OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC, - TASKS_SIZE, DayTasksSize_, - TASKS_NUMBER, DayTasksNumber_); + TASKS_SIZE, &dayTasksSize_, + TASKS_NUMBER, &dayTasksNumber_); } void TaskStatistics::StartTimerThread() @@ -90,8 +88,8 @@ void TaskStatistics::StartTimerThread() DOWNLOAD_HILOGD("taskRun next interval: %{public}d", nextReportInterval); sleep(nextReportInterval); ReportStatistics(); - this->DayTasksNumber_ = 0; - this->DayTasksSize_ = 0; + this->dayTasksNumber_ = 0; + this->dayTasksSize_ = 0; } }; std::thread th = std::thread(fun); diff --git a/download/dfx/event/statistics/task_statistics.h b/download/dfx/event/statistics/task_statistics.h index 21bb2ca..823a39f 100644 --- a/download/dfx/event/statistics/task_statistics.h +++ b/download/dfx/event/statistics/task_statistics.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,6 @@ #ifndef TASK_STATISTICS_H #define TASK_STATISTICS_H -#include #include namespace OHOS::Request::Download { @@ -42,13 +41,12 @@ private: static constexpr const char *REQUEST_TASK_INFO_STATISTICS = "REQUEST_TASK_INFO_STATISTICS"; static constexpr const char *TASKS_SIZE = "TASKS_SIZE"; static constexpr const char *TASKS_NUMBER = "TASKS_NUMBER"; - static constexpr const int32_t ONE_DAY_SEC = 24 * 3600; - static constexpr const int32_t ONE_HOUR_SEC = 3600; - static constexpr const int32_t ONE_MINUTE_SEC = 60; + static constexpr int32_t ONE_DAY_SEC = 24 * 3600; + static constexpr int32_t ONE_HOUR_SEC = 3600; + static constexpr int32_t ONE_MINUTE_SEC = 60; - std::mutex mutex_; - int64_t DayTasksSize_ {0}; - int32_t DayTasksNumber_ {0}; + std::atomic dayTasksNumber_ {0}; + std::atomic dayTasksSize_ {0}; bool running_ { false }; }; } diff --git a/download/interfaces/kits/js/napi/download_single/include/download_info.h b/download/interfaces/kits/js/napi/download_single/include/download_info.h index 6f52a42..de4177f 100644 --- a/download/interfaces/kits/js/napi/download_single/include/download_info.h +++ b/download/interfaces/kits/js/napi/download_single/include/download_info.h @@ -76,6 +76,7 @@ public: [[nodiscard]] uint32_t GetNetworkType() const; [[nodiscard]] bool GetMetered() const; [[nodiscard]] bool GetRoaming() const; + [[nodiscard]] std::string GetTaskType() const; void Dump(); private: @@ -98,12 +99,14 @@ private: std::string targetURI_; std::string downloadTitle_; + + std::string taskType_; uint32_t downloadTotalBytes_; - bool enableMetered_; - bool enableRoaming_; - uint32_t networkType_; + bool enableMetered_ {false}; + bool enableRoaming_ {false}; + uint32_t networkType_ {0}; }; } // namespace OHOS::Request::Download #endif /* DOWNLOAD_INFO_H */ diff --git a/download/interfaces/kits/js/napi/download_single/src/download_info.cpp b/download/interfaces/kits/js/napi/download_single/src/download_info.cpp index ddeb331..5d7d68c 100644 --- a/download/interfaces/kits/js/napi/download_single/src/download_info.cpp +++ b/download/interfaces/kits/js/napi/download_single/src/download_info.cpp @@ -21,7 +21,7 @@ namespace OHOS::Request::Download { DownloadInfo::DownloadInfo() : description_(""), downloadedBytes_(0), downloadId_(0), failedReason_(ERROR_UNKNOWN), fileName_(""), filePath_(""), pausedReason_(PAUSED_UNKNOWN), status_(SESSION_UNKNOWN), targetURI_(""), downloadTitle_(""), - downloadTotalBytes_(0) { + taskType_("download"), downloadTotalBytes_(0) { } void DownloadInfo::SetDescription(const std::string &description) @@ -144,6 +144,11 @@ const std::string &DownloadInfo::GetDownloadTitle() const return downloadTitle_; } +std::string DownloadInfo::GetTaskType() const +{ + return taskType_; +} + uint32_t DownloadInfo::GetDownloadTotalBytes() const { return downloadTotalBytes_; diff --git a/hisysevent.yaml b/hisysevent.yaml index 2ddf2f1..8c167dc 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -46,13 +46,13 @@ REQUEST_SERVICE_START_FAULT: REQUEST_TASK_FAULT: __BASE: {type: FAULT, level: MINOR, desc: The request task fail } TASK_TYPE: {type: STRING, desc: Task type} - TOTAL_FILE_NUM: {type: INT32, desc: Total number of documents } - FAIL_FILE_NUM: {type: INT32, desc: Number of failed files } - SUCCESS_FILE_NUM: {type: INT32, desc: Number of successful files } + TOTAL_FILE_NUM: {type: UINT32, desc: Total number of documents } + FAIL_FILE_NUM: {type: UINT32, desc: Number of failed files } + SUCCESS_FILE_NUM: {type: UINT32, desc: Number of successful files } ERROR_INFO: {type: INT32, desc: Error code } REQUEST_TASK_INFO_STATISTICS: __BASE: {type: STATISTIC, level: MINOR, desc: Statistics of download tasks } - TASKS_SIZE: {type: INT64, desc: Download tasks size} - TASKS_NUMBER: {type: INT32, desc: Download tasks number} + TASKS_SIZE: {type: UINT64, desc: Download tasks size} + TASKS_NUMBER: {type: UINT32, desc: Download tasks number} diff --git a/upload/frameworks/libs/include/upload_common.h b/upload/frameworks/libs/include/upload_common.h index e4e49b8..67e9b3f 100644 --- a/upload/frameworks/libs/include/upload_common.h +++ b/upload/frameworks/libs/include/upload_common.h @@ -24,8 +24,8 @@ enum Type { }; struct TaskResult { - int32_t successCount {0}; - int32_t failCount {0}; + uint32_t successCount {0}; + uint32_t failCount {0}; int32_t errorCode {0}; }; diff --git a/upload/frameworks/libs/src/obtain_file.cpp b/upload/frameworks/libs/src/obtain_file.cpp index f6024c2..fe90178 100644 --- a/upload/frameworks/libs/src/obtain_file.cpp +++ b/upload/frameworks/libs/src/obtain_file.cpp @@ -59,10 +59,10 @@ uint32_t ObtainFile::GetDataAbilityFile(FILE **file, std::string &fileUri, { uint32_t ret = UPLOAD_ERRORCODE_NO_ERROR; FILE *filePtr = nullptr; - int32_t fileLength = 0; + uint32_t fileLength = 0; do { - int32_t fd = fileAdapter_->DataAbilityOpenFile(fileUri, context); + uint32_t fd = fileAdapter_->DataAbilityOpenFile(fileUri, context); if (fd == -1) { UPLOAD_HILOGE(UPLOAD_MODULE_FRAMEWORK, "ObtainFile::GetDataAbilityFile, open file error."); ret = UPLOAD_ERRORCODE_GET_FILE_ERROR;