1 /*
2 * Copyright (C) 2024 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 "gallery_report.h"
16
17 #include <sstream>
18
19 #include "media_log.h"
20 #include "hisysevent.h"
21 #include "backup_database_utils.h"
22 #include "backup_const.h"
23 #include "gallery_media_count_statistic.h"
24 #include "external_files_count_statistic.h"
25
26 namespace OHOS::Media {
27 static constexpr char MEDIA_LIBRARY[] = "MEDIALIBRARY";
Load()28 std::vector<AlbumMediaStatisticInfo> GalleryReport::Load()
29 {
30 std::vector<AlbumMediaStatisticInfo> galleryStatInfos = GalleryMediaCountStatistic()
31 .SetGalleryRdb(this->galleryRdb_)
32 .SetSceneCode(this->sceneCode_)
33 .SetTaskId(this->taskId_)
34 .SetShouldIncludeSd(this->shouldIncludeSd_)
35 .Load();
36 std::vector<AlbumMediaStatisticInfo> externalStatInfos = ExternalFilesCountStatistic()
37 .SetExternalRdb(this->externalRdb_)
38 .SetSceneCode(this->sceneCode_)
39 .SetTaskId(this->taskId_)
40 .Load();
41 galleryStatInfos.insert(galleryStatInfos.end(), externalStatInfos.begin(), externalStatInfos.end());
42 return galleryStatInfos;
43 }
44
ToString(const AlbumMediaStatisticInfo & info)45 std::string GalleryReport::ToString(const AlbumMediaStatisticInfo &info)
46 {
47 std::stringstream ss;
48 ss << "{"
49 << "\"sceneCode\":\"" << info.sceneCode << "\", "
50 << "\"taskId\":\"" << info.taskId << "\", "
51 << "\"albumName\":\"" << info.albumName << "\", "
52 << "\"totalCount\":" << info.totalCount << ", "
53 << "\"imageCount\":" << info.imageCount << ", "
54 << "\"videoCount\":" << info.videoCount << ", "
55 << "\"hiddenCount\":" << info.hiddenCount << ", "
56 << "\"trashedCount\":" << info.trashedCount << ", "
57 << "\"cloudCount\":" << info.cloudCount << ", "
58 << "\"favoriteCount\":" << info.favoriteCount << ", "
59 << "\"burstTotalCount\":" << info.burstTotalCount << ", "
60 << "\"burstCoverCount\":" << info.burstCoverCount << "}";
61 return ss.str();
62 }
63
Report()64 int32_t GalleryReport::Report()
65 {
66 std::vector<AlbumMediaStatisticInfo> albumMediaStatisticInfos = this->Load();
67 for (const auto &info : albumMediaStatisticInfos) {
68 MEDIA_INFO_LOG("gallery analyze result: %{public}s", this->ToString(info).c_str());
69 int32_t ret = HiSysEventWrite(MEDIA_LIBRARY,
70 "MEDIALIB_BACKUP_MEDIA_STAT",
71 HiviewDFX::HiSysEvent::EventType::STATISTIC,
72 "SCENE_CODE",
73 info.sceneCode,
74 "TASK_ID",
75 info.taskId,
76 "ALBUM_NAME",
77 info.albumName,
78 "TOTAL_COUNT",
79 info.totalCount,
80 "IMAGE_COUNT",
81 info.imageCount,
82 "VIDEO_COUNT",
83 info.videoCount,
84 "HIDDEN_COUNT",
85 info.hiddenCount,
86 "TRASHED_COUNT",
87 info.trashedCount,
88 "FAVORITE_COUNT",
89 info.favoriteCount,
90 "CLOUD_COUNT",
91 info.cloudCount,
92 "BURST_COVER_COUNT",
93 info.burstCoverCount,
94 "BURST_TOTAL_COUNT",
95 info.burstTotalCount);
96 if (ret != 0) {
97 MEDIA_ERR_LOG("GalleryMediaCountStatistic error:%{public}d", ret);
98 }
99 }
100 return 0;
101 }
102 } // namespace OHOS::Media