diff --git a/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/BUILD.gn b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/BUILD.gn index f963c651c9ae9162b8d653600b7e4017657b1b88..29cad457703c9a9d3d2a0219155ff43618722ce3 100644 --- a/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/BUILD.gn +++ b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("medialibrary_dfx_test") { "./src/dfx_deprecated_perm_usage_test.cpp", "./src/dfx_moving_photo_test.cpp", "./src/medialibrary_dfx_test.cpp", + "./src/medialibrary_dfx_patch_test.cpp", "./src/mock_medialibrary_subscriber.cpp", ] deps = [ diff --git a/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_patch_test.cpp b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_patch_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c065b0e1f7a89e57d1e0057b3d6cd78db904abec --- /dev/null +++ b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_patch_test.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "medialibrary_dfx_test.h" + +#include +#include + +#include "dfx_cloud_manager.h" +#include "dfx_collector.h" +#include "dfx_const.h" +#include "dfx_database_utils.h" +#include "dfx_manager.h" +#include "dfx_reporter.h" +#include "dfx_utils.h" +#include "hisysevent.h" +#include "medialibrary_astc_stat.h" +#include "medialibrary_errno.h" +#include "medialibrary_inotify.h" +#include "medialibrary_rdbstore.h" +#include "media_file_utils.h" +#include "photo_album_column.h" +#include "preferences.h" +#include "preferences_helper.h" +#include "parameters.h" + +using namespace std; +using namespace OHOS; +using namespace testing::ext; + +namespace OHOS { +namespace Media { + +class MediaLibraryDfxPatchTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void MediaLibraryDfxPatchTest::SetUpTestCase(void) +{ + DfxManager::GetInstance(); +} +void MediaLibraryDfxPatchTest::TearDownTestCase(void) {} + +// SetUp:Execute before each test case +void MediaLibraryDfxPatchTest::SetUp() +{ + DfxManager::GetInstance()->isInitSuccess_ = true; +} + +void MediaLibraryDfxPatchTest::TearDown(void) {} + +HWTEST_F(MediaLibraryDfxPatchTest, ReportSyncStat_001, TestSize.Level0) +{ + DfxReporter dfxReporter; + std::string taskId = "0000110"; + CloudSyncInfo cloudSyncInfo{}; + CloudSyncStat cloudSyncStat{}; + std::string syncInfo = "syncInfoDfx"; + int32_t southDeviceType = 0; + int32_t ret = dfxReporter.ReportSyncStat(taskId, cloudSyncInfo, cloudSyncStat, syncInfo, southDeviceType); + EXPECT_EQ(ret, E_OK); +} + +HWTEST_F(MediaLibraryDfxPatchTest, ReportSyncFault_001, TestSize.Level0) +{ + DfxReporter dfxReporter; + std::string taskId = "0000110"; + std::string position = "2"; + SyncFaultEvent event; + int32_t southDeviceType = 0; + int32_t ret = dfxReporter.ReportSyncFault(taskId, position, event, southDeviceType); + EXPECT_EQ(ret, E_OK); +} +} // namespace Media +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_test.cpp b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_test.cpp index c0ef247050128c24cb6575f4e0fa04ec59e23c79..b173ee82f986d42fffaf5e38605fa1f6c6f606c1 100644 --- a/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/medialibrary_dfx_test/src/medialibrary_dfx_test.cpp @@ -602,6 +602,7 @@ HWTEST_F(MediaLibraryDfxTest, medialib_dfx_ReportPhotoInfo_test_001, TestSize.Le PhotoStatistics stats = {}; DfxReporter dfxReporter; dfxReporter.ReportPhotoInfo(stats); + stats.southDeviceType = 0; int ret = HiSysEventWrite( MEDIA_LIBRARY, "MEDIALIB_PHOTO_INFO", @@ -611,7 +612,8 @@ HWTEST_F(MediaLibraryDfxTest, medialib_dfx_ReportPhotoInfo_test_001, TestSize.Le "CLOUD_IMAGE_COUNT", stats.cloudImageCount, "CLOUD_VIDEO_COUNT", stats.cloudVideoCount, "SHARED_IMAGE_COUNT", stats.sharedImageCount, - "SHARED_VIDEO_COUNT", stats.sharedVideoCount); + "SHARED_VIDEO_COUNT", stats.sharedVideoCount, + "SOUTH_DEVICE_TYPE", stats.southDeviceType); EXPECT_EQ(ret, E_OK); } @@ -720,9 +722,10 @@ HWTEST_F(MediaLibraryDfxTest, medialib_dfx_ReportCloudSyncThumbGenerationStatus_ int32_t downloadedThumb = 1; int32_t generatedThumb = 1; int32_t totalDownload = 0; + int32_t southDeviceType = 0; DfxReporter dfxReporter; int32_t result = dfxReporter.ReportCloudSyncThumbGenerationStatus(downloadedThumb, - generatedThumb, totalDownload); + generatedThumb, totalDownload, southDeviceType); EXPECT_EQ(result, 0); } @@ -731,9 +734,10 @@ HWTEST_F(MediaLibraryDfxTest, medialib_dfx_ReportCloudSyncThumbGenerationStatus_ int32_t downloadedThumb = 1; int32_t generatedThumb = 1; int32_t totalDownload = 1; + int32_t southDeviceType = 0; DfxReporter dfxReporter; int32_t result = dfxReporter.ReportCloudSyncThumbGenerationStatus(downloadedThumb, - generatedThumb, totalDownload); + generatedThumb, totalDownload, southDeviceType); EXPECT_EQ(result, 0); } diff --git a/frameworks/services/media_dfx/include/dfx_const.h b/frameworks/services/media_dfx/include/dfx_const.h index fa6aced21c20c00baba0ee91c143e42a380ea1fa..8d564106693e9a0fb77832b3bf3e6e3cfbcf6c82 100644 --- a/frameworks/services/media_dfx/include/dfx_const.h +++ b/frameworks/services/media_dfx/include/dfx_const.h @@ -181,6 +181,8 @@ struct PhotoRecordInfo { int64_t slaveDbFileSize; int32_t duplicateLpathCount; int32_t abnormalLpathCount; + int32_t photoWaitUploadCloudCount; + int32_t photoWaitUploadHdcCount; }; struct AdaptationToMovingPhotoInfo { diff --git a/frameworks/services/media_dfx/include/dfx_reporter.h b/frameworks/services/media_dfx/include/dfx_reporter.h index b766a66f414d98f23e2d6d1a36e7b6c16b01d7c8..774b8a25090b24a431fc83080d25c7e534047a7e 100644 --- a/frameworks/services/media_dfx/include/dfx_reporter.h +++ b/frameworks/services/media_dfx/include/dfx_reporter.h @@ -77,6 +77,7 @@ struct PhotoStatistics { int32_t cloudVideoCount; // 纯云端视频数量 int32_t sharedImageCount; // 端云共存照片数量 int32_t sharedVideoCount; // 端云共存视频数量 + int32_t southDeviceType; }; struct LcdAndAstcCount { @@ -138,7 +139,7 @@ public: void ReportAdaptationToMovingPhoto(); void ReportAlibHeifDuplicate(); static int32_t ReportCloudSyncThumbGenerationStatus(const int32_t& downloadedThumb, const int32_t& generatedThumb, - const int32_t& totalDownload); + const int32_t& totalDownload, const int32_t& southDeviceType); EXPORT static void ReportStartResult(int32_t scene, int32_t errorCode, int32_t startTime); void ReportPhotoRecordInfo(); static int32_t ReportMedialibraryAPI(const std::string& callerPackage, const std::string& saveUri); @@ -149,9 +150,9 @@ public: static int32_t ReportPhotoError(const PhotoErrorCount& reportData); static int32_t ReportSyncFault(const std::string& taskId, const std::string& position, - const SyncFaultEvent& event); + const SyncFaultEvent& event, const int32_t& southDeviceType); static int32_t ReportSyncStat(const std::string& taskId, const CloudSyncInfo& info, const CloudSyncStat& stat, - const std::string& syncInfo); + const std::string& syncInfo, const int32_t& southDeviceType); void ReportPhotoSizeAndResolutionInfo(const QuerySizeAndResolution& querySizeAndResolution, const std::string& photoMimeType); void ReportAccurateRefreshResult(const AccurateRefreshDfxDataPoint& reportData); diff --git a/frameworks/services/media_dfx/src/dfx_database_utils.cpp b/frameworks/services/media_dfx/src/dfx_database_utils.cpp index 1ab6b905b5f44cdf9dde2545abd23951a3295ceb..f22b88fff8a65e7e47f716aab9163fc23ff7bb15 100644 --- a/frameworks/services/media_dfx/src/dfx_database_utils.cpp +++ b/frameworks/services/media_dfx/src/dfx_database_utils.cpp @@ -32,6 +32,7 @@ #include "preferences.h" #include "preferences_helper.h" #include "power_efficiency_manager.h" +#include "settings_data_manager.h" #include "userfile_manager_types.h" namespace OHOS { @@ -52,6 +53,7 @@ const int32_t FILE_HEIGHT_AND_WIDTH_1440 = 1440; const int32_t FILE_HEIGHT_AND_WIDTH_2000 = 2000; const int32_t FILE_HEIGHT_AND_WIDTH_4000 = 4000; const int64_t PHOTO_FILE_SIZE = 1024; + static const std::vector> sizeRanges = { {100, "size100K"}, {250, "size250K"}, @@ -274,6 +276,35 @@ static void BuildDbInfo(PhotoRecordInfo &photoRecordInfo) } } +static void FillWaitUploadCount(PhotoRecordInfo &photoRecordInfo, bool &ret) +{ + const string filterCondition = MediaColumn::MEDIA_TIME_PENDING + " = 0 AND " + + PhotoColumn::PHOTO_SYNC_STATUS + " = " + + to_string(static_cast(SyncStatusType::TYPE_VISIBLE)) + " AND " + + PhotoColumn::PHOTO_CLEAN_FLAG + " = " + + to_string(static_cast(CleanType::TYPE_NOT_CLEAN)); + auto switchStatus = SettingsDataManager::GetPhotosSyncSwitchStatus(); + if (switchStatus == SwitchStatus::CLOUD) { + const string photoWaitUploadCloudCountQuerySql = "SELECT COUNT(*) AS " + RECORD_COUNT + " FROM " + + PhotoColumn::PHOTOS_TABLE + " WHERE " + PhotoColumn::PHOTO_POSITION + " = " + + to_string(static_cast(PhotoPositionType::LOCAL)) + " AND " + filterCondition; + ret = ParseResultSet(photoWaitUploadCloudCountQuerySql, 0, photoRecordInfo.photoWaitUploadCloudCount) && ret; + photoRecordInfo.photoWaitUploadHdcCount = -1; + } else if (switchStatus == SwitchStatus::HDC) { + const string photoWaitUploadHdcCountQuerySql = "SELECT COUNT(*) AS " + RECORD_COUNT + " FROM " + + PhotoColumn::PHOTOS_TABLE + " WHERE " + PhotoColumn::PHOTO_POSITION + " = " + + to_string(static_cast(PhotoPositionType::LOCAL)) + " AND " + filterCondition; + ret = ParseResultSet(photoWaitUploadHdcCountQuerySql, 0, photoRecordInfo.photoWaitUploadHdcCount) && ret; + photoRecordInfo.photoWaitUploadCloudCount = -1; + } else if (switchStatus == SwitchStatus::CLOSE) { + photoRecordInfo.photoWaitUploadCloudCount = 0; + photoRecordInfo.photoWaitUploadHdcCount = 0; + } else { + photoRecordInfo.photoWaitUploadCloudCount = -1; + photoRecordInfo.photoWaitUploadHdcCount = -1; + } +} + int32_t DfxDatabaseUtils::QueryPhotoRecordInfo(PhotoRecordInfo &photoRecordInfo) { const string filterCondition = MediaColumn::MEDIA_TIME_PENDING + " = 0 AND " + @@ -309,7 +340,7 @@ int32_t DfxDatabaseUtils::QueryPhotoRecordInfo(PhotoRecordInfo &photoRecordInfo) const string duplicateLpathCountQuerySql = GetDuplicateLpathCountQuerrySql(); const string abnormalLpathCountQuerySql = GetAbnormalLpathCountQuerySql(); - int32_t ret = ParseResultSet(imageAndVideoCountQuerySql, MEDIA_TYPE_VIDEO, photoRecordInfo.videoCount); + bool ret = ParseResultSet(imageAndVideoCountQuerySql, MEDIA_TYPE_VIDEO, photoRecordInfo.videoCount); ret = ParseResultSet(imageAndVideoCountQuerySql, MEDIA_TYPE_IMAGE, photoRecordInfo.imageCount) && ret; ret = ParseResultSet(abnormalSizeCountQuerySql, 0, photoRecordInfo.abnormalSizeCount) && ret; ret = ParseResultSet(abnormalWidthHeightQuerySql, 0, photoRecordInfo.abnormalWidthOrHeightCount) && ret; @@ -317,7 +348,7 @@ int32_t DfxDatabaseUtils::QueryPhotoRecordInfo(PhotoRecordInfo &photoRecordInfo) ret = ParseResultSet(totalAbnormalRecordSql, 0, photoRecordInfo.toBeUpdatedRecordCount) && ret; ret = ParseResultSet(duplicateLpathCountQuerySql, 0, photoRecordInfo.duplicateLpathCount) && ret; ret = ParseResultSet(abnormalLpathCountQuerySql, 0, photoRecordInfo.abnormalLpathCount) && ret; - + FillWaitUploadCount(photoRecordInfo, ret); BuildDbInfo(photoRecordInfo); return ret; } diff --git a/frameworks/services/media_dfx/src/dfx_manager.cpp b/frameworks/services/media_dfx/src/dfx_manager.cpp index 30032bbcf94c53558cb6ca54a0fac68d2f13b057..4c201a3c10f2fa1a0e318e1cd64b793f93cf48f7 100644 --- a/frameworks/services/media_dfx/src/dfx_manager.cpp +++ b/frameworks/services/media_dfx/src/dfx_manager.cpp @@ -17,6 +17,7 @@ #include #include "dfx_manager.h" +#include "cloud_media_context.h" #include "dfx_cloud_manager.h" #include "dfx_utils.h" #include "media_file_utils.h" @@ -37,6 +38,7 @@ #include "hi_audit.h" #include "medialibrary_errno.h" #include "medialibrary_unistore_manager.h" +#include "settings_data_manager.h" using namespace std; @@ -277,7 +279,7 @@ static void HandlePhotoInfo(std::shared_ptr& dfxReporter) stats.localImageCount, stats.localVideoCount, stats.cloudImageCount, stats.cloudVideoCount, stats.sharedImageCount, stats.sharedVideoCount); - + stats.southDeviceType = static_cast(SettingsDataManager::GetPhotosSyncSwitchStatus()); dfxReporter->ReportPhotoInfo(stats); } @@ -787,7 +789,8 @@ void EndState::Process(CloudSyncDfxManager& manager) } SetReported(true); manager.ShutDownTimer(); - DfxReporter::ReportCloudSyncThumbGenerationStatus(downloadedThumb, generatedThumb, totalDownload); + DfxReporter::ReportCloudSyncThumbGenerationStatus(downloadedThumb, generatedThumb, totalDownload, + static_cast(SettingsDataManager::GetPhotosSyncSwitchStatus())); } } @@ -816,7 +819,8 @@ void CloudSyncDfxManager::StartTimer() "download: %{public}d, generate: %{public}d", downloadedThumb, generatedThumb); SetReported(true); } - DfxReporter::ReportCloudSyncThumbGenerationStatus(downloadedThumb, generatedThumb, totalDownload); + DfxReporter::ReportCloudSyncThumbGenerationStatus(downloadedThumb, generatedThumb, totalDownload, + static_cast(SettingsDataManager::GetPhotosSyncSwitchStatus())); } }; timerId_ = timer_.Register(timerCallback, SIX_HOUR * TO_MILLION, false); @@ -1026,13 +1030,14 @@ void DfxManager::HandleSyncEnd(const int32_t stopReason) break; } } - - DfxReporter::ReportSyncStat(taskId_, syncInfo_, stat, syncInfo); + DfxReporter::ReportSyncStat(taskId_, syncInfo_, stat, syncInfo, + CloudSync::CloudMediaContext::GetInstance().GetCloudType()); } void DfxManager::HandleReportSyncFault(const std::string& position, const SyncFaultEvent& event) { - DfxReporter::ReportSyncFault(taskId_, position, event); + DfxReporter::ReportSyncFault(taskId_, position, event, + CloudSync::CloudMediaContext::GetInstance().GetCloudType()); } void DfxManager::HandleAccurateRefreshTimeOut(const AccurateRefreshDfxDataPoint& reportData) diff --git a/frameworks/services/media_dfx/src/dfx_reporter.cpp b/frameworks/services/media_dfx/src/dfx_reporter.cpp index f018aa807bdfcf5edbbebfa6ed3e2aa82599a8a4..42f11652c98c3bcb135e6bf300d7469626c77367 100644 --- a/frameworks/services/media_dfx/src/dfx_reporter.cpp +++ b/frameworks/services/media_dfx/src/dfx_reporter.cpp @@ -253,7 +253,8 @@ void DfxReporter::ReportPhotoInfo(const PhotoStatistics& stats) "CLOUD_IMAGE_COUNT", stats.cloudImageCount, "CLOUD_VIDEO_COUNT", stats.cloudVideoCount, "SHARED_IMAGE_COUNT", stats.sharedImageCount, - "SHARED_VIDEO_COUNT", stats.sharedVideoCount); + "SHARED_VIDEO_COUNT", stats.sharedVideoCount, + "SOUTH_DEVICE_TYPE", stats.southDeviceType); if (ret != 0) { MEDIA_ERR_LOG("ReportPhotoInfo error:%{public}d", ret); } @@ -394,7 +395,7 @@ std::string SecondsToTime(const int64_t& seconds) } int32_t DfxReporter::ReportCloudSyncThumbGenerationStatus(const int32_t& downloadedThumb, - const int32_t& generatedThumb, const int32_t& totalDownload) + const int32_t& generatedThumb, const int32_t& totalDownload, const int32_t& southDeviceType) { if (totalDownload == 0) { return 0; @@ -421,7 +422,8 @@ int32_t DfxReporter::ReportCloudSyncThumbGenerationStatus(const int32_t& downloa "DOWNLOADED_THUMB_RATIO", downloadedThumb / total, "GENERATED_THUMB_NUM", generatedThumb, "GENERATED_THUMB_RATIO", generatedThumb / total, - "CLOUD_DOWN_TOTAL_DURATION", SecondsToTime(cost)); + "CLOUD_DOWN_TOTAL_DURATION", SecondsToTime(cost), + "SOUTH_DEVICE_TYPE", southDeviceType); if (ret != 0) { MEDIA_ERR_LOG("Report CloudSyncThumbGenerationStatus error:%{public}d", ret); } @@ -455,6 +457,8 @@ void DfxReporter::ReportPhotoRecordInfo() int64_t dbFileSize = photoRecordInfo.dbFileSize; int32_t duplicateLpathCount = photoRecordInfo.duplicateLpathCount; int32_t abnormalLpathCount = photoRecordInfo.abnormalLpathCount; + int32_t photoWaitUploadCloudCount = photoRecordInfo.photoWaitUploadCloudCount; + int32_t photoWaitUploadHdcCount = photoRecordInfo.photoWaitUploadHdcCount; int ret = HiSysEventWrite( MEDIA_LIBRARY, "MEDIALIB_DATABASE_INFO", @@ -469,6 +473,8 @@ void DfxReporter::ReportPhotoRecordInfo() "ABNORMAL_COUNT_TO_UPDATE", toBeUpdatedRecordCount, "DUPLICATE_LPATH_COUNT", duplicateLpathCount, "ABNORMAL_LPATH_COUNT", abnormalLpathCount, + "PHOTO_WAIT_UPLOAD_CLOUD_COUNT", photoWaitUploadCloudCount, + "PHOTO_WAIT_UPLOAD_HDC_COUNT", photoWaitUploadHdcCount, "WATCH_LIST_INFO", GetWatchListInfo()); if (ret != 0) { MEDIA_ERR_LOG("ReportPhotoRecordInfo error:%{public}d", ret); @@ -605,7 +611,7 @@ int32_t DfxReporter::ReportPhotoError(const PhotoErrorCount& reportData) } int32_t DfxReporter::ReportSyncFault(const std::string& taskId, const std::string& position, - const SyncFaultEvent& event) + const SyncFaultEvent& event, const int32_t& southDeviceType) { int32_t ret = HiSysEventWrite( MEDIA_LIBRARY, @@ -616,7 +622,8 @@ int32_t DfxReporter::ReportSyncFault(const std::string& taskId, const std::strin "FAULT_TYPE", static_cast(event.type), "FAULT_ERROR_CODE", event.errorCode, "FUNCTION_NAME", position, - "MESSAGE", event.message); + "MESSAGE", event.message, + "SOUTH_DEVICE_TYPE", southDeviceType); if (ret != E_OK) { MEDIA_ERR_LOG("report ReportSyncFault error %{public}d", ret); } @@ -624,7 +631,7 @@ int32_t DfxReporter::ReportSyncFault(const std::string& taskId, const std::strin } int32_t DfxReporter::ReportSyncStat(const std::string& taskId, const CloudSyncInfo& info, const CloudSyncStat& stat, - const std::string& syncInfo) + const std::string& syncInfo, const int32_t& southDeviceType) { int32_t ret = HiSysEventWrite( MEDIA_LIBRARY, @@ -642,7 +649,8 @@ int32_t DfxReporter::ReportSyncStat(const std::string& taskId, const CloudSyncIn "UPLOAD_ALBUM", stat.uploadAlbum, "DOWNLOAD_ALBUM", stat.downloadAlbum, "UPLOAD_META_ERR", stat.uploadMetaErr, - "SYNC_INFO", syncInfo); + "SYNC_INFO", syncInfo, + "SOUTH_DEVICE_TYPE", southDeviceType); if (ret != E_OK) { MEDIA_ERR_LOG("report ReportSyncStat error %{public}d", ret); }