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_media_count_statistic.h"
16
17 #include "media_log.h"
18 #include "backup_database_utils.h"
19 #include "backup_const.h"
20 #include "media_backup_report_data_type.h"
21 #include "statistic_processor.h"
22 #include "media_file_utils.h"
23
24 namespace OHOS::Media {
Load()25 std::vector<AlbumMediaStatisticInfo> GalleryMediaCountStatistic::Load()
26 {
27 if (this->galleryRdb_ == nullptr) {
28 MEDIA_ERR_LOG("galleryRdb_ is nullptr, Maybe init failed.");
29 return {};
30 }
31 std::vector<AlbumMediaStatisticInfo> infoList = {
32 // data-transfer statistic info.
33 this->GetAllStatInfo(),
34 this->GetAllImageStatInfo(),
35 this->GetAllVideoStatInfo(),
36 this->GetAllRestoreStatInfo(),
37 this->GetAllRestoreImageStatInfo(),
38 this->GetAllRestoreVideoStatInfo(),
39 // other statistic info.
40 this->GetSdCardStatInfo(),
41 this->GetDuplicateStatInfo(),
42 this->GetAppTwinStatInfo(),
43 this->GetLiveStatInfo(),
44 this->GetTempInfo(),
45 this->GetNotSyncInfo(),
46 this->GetGalleryAlbumCountInfo(),
47 // statistic info.
48 this->GetImageAlbumInfo(),
49 this->GetVideoAlbumInfo(),
50 // folder info.
51 this->GetFavoriteAlbumStatInfo(),
52 this->GetTrashedAlbumStatInfo(),
53 };
54 // key album statistic info.
55 std::vector<AlbumMediaStatisticInfo> importsAlbumList = this->GetAlbumInfoByLPath("/Pictures/cloud/Imports");
56 infoList.insert(infoList.end(), importsAlbumList.begin(), importsAlbumList.end());
57 std::vector<AlbumMediaStatisticInfo> hiddenAlbumList = this->GetAlbumInfoByLPath("/Pictures/hiddenAlbum");
58 infoList.insert(infoList.end(), hiddenAlbumList.begin(), hiddenAlbumList.end());
59 // key album of album_plugin.
60 std::vector<AlbumMediaStatisticInfo> cameraAlbumList = this->GetAlbumInfoByName("相机");
61 infoList.insert(infoList.end(), cameraAlbumList.begin(), cameraAlbumList.end());
62 std::vector<AlbumMediaStatisticInfo> screenShotAlbumList = this->GetAlbumInfoByName("截图");
63 infoList.insert(infoList.end(), screenShotAlbumList.begin(), screenShotAlbumList.end());
64 std::vector<AlbumMediaStatisticInfo> weiXinAlbumList = this->GetAlbumInfoByName("微信");
65 infoList.insert(infoList.end(), weiXinAlbumList.begin(), weiXinAlbumList.end());
66 std::vector<AlbumMediaStatisticInfo> weiboAlbumList = this->GetAlbumInfoByName("微博");
67 infoList.insert(infoList.end(), weiboAlbumList.begin(), weiboAlbumList.end());
68 std::vector<AlbumMediaStatisticInfo> shareAlbumList = this->GetAlbumInfoByName("华为分享");
69 infoList.insert(infoList.end(), shareAlbumList.begin(), shareAlbumList.end());
70 std::vector<AlbumMediaStatisticInfo> otherAlbumList = this->GetAlbumInfoByName("其它");
71 infoList.insert(infoList.end(), otherAlbumList.begin(), otherAlbumList.end());
72 return infoList;
73 }
74
GetCount(const std::string & query)75 int32_t GalleryMediaCountStatistic::GetCount(const std::string &query)
76 {
77 return BackupDatabaseUtils::QueryInt(this->galleryRdb_, query, CUSTOM_COUNT);
78 }
79
QueryGalleryAllCount(SearchCondition searchCondition)80 int32_t GalleryMediaCountStatistic::QueryGalleryAllCount(SearchCondition searchCondition)
81 {
82 if (this->galleryRdb_ == nullptr) {
83 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
84 return 0;
85 }
86 int32_t mediaType = searchCondition.GetMediaType();
87 int32_t hiddenType = searchCondition.GetHiddenType();
88 int32_t trashedType = searchCondition.GetTrashedType();
89 int32_t cloudType = searchCondition.GetCloudType();
90 int32_t favoriteType = searchCondition.GetFavoriteType();
91 int32_t burstType = searchCondition.GetBurstType();
92 std::vector<NativeRdb::ValueObject> params = {mediaType,
93 mediaType,
94 hiddenType,
95 hiddenType,
96 hiddenType,
97 trashedType,
98 trashedType,
99 trashedType,
100 cloudType,
101 cloudType,
102 cloudType,
103 favoriteType,
104 favoriteType,
105 favoriteType,
106 burstType,
107 burstType,
108 burstType};
109 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_ALL_GALLERY_COUNT, params);
110 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
111 return 0;
112 }
113 return GetInt32Val("count", resultSet);
114 }
115
QueryAlbumGalleryCount(SearchCondition searchCondition)116 int32_t GalleryMediaCountStatistic::QueryAlbumGalleryCount(SearchCondition searchCondition)
117 {
118 if (this->galleryRdb_ == nullptr) {
119 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
120 return 0;
121 }
122 int32_t mediaType = searchCondition.GetMediaType();
123 int32_t hiddenType = searchCondition.GetHiddenType();
124 int32_t trashedType = searchCondition.GetTrashedType();
125 int32_t cloudType = searchCondition.GetCloudType();
126 int32_t favoriteType = searchCondition.GetFavoriteType();
127 int32_t burstType = searchCondition.GetBurstType();
128 std::vector<NativeRdb::ValueObject> params = {mediaType,
129 mediaType,
130 hiddenType,
131 hiddenType,
132 hiddenType,
133 trashedType,
134 trashedType,
135 trashedType,
136 cloudType,
137 cloudType,
138 cloudType,
139 favoriteType,
140 favoriteType,
141 favoriteType,
142 burstType,
143 burstType,
144 burstType};
145 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_ALBUM_GALLERY_COUNT, params);
146 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
147 return 0;
148 }
149 return GetInt32Val("count", resultSet);
150 }
151
152 /**
153 * @brief Get the row count of gallery_media.
154 * @param mediaType - 0 all, 1 picture, 3 video
155 */
GetGalleryMediaAllRestoreCount(SearchCondition searchCondition)156 int32_t GalleryMediaCountStatistic::GetGalleryMediaAllRestoreCount(SearchCondition searchCondition)
157 {
158 if (this->galleryRdb_ == nullptr) {
159 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
160 return 0;
161 }
162 int32_t mediaType = searchCondition.GetMediaType();
163 int32_t hiddenType = searchCondition.GetHiddenType();
164 int32_t trashedType = searchCondition.GetTrashedType();
165 int32_t cloudType = searchCondition.GetCloudType();
166 int32_t favoriteType = searchCondition.GetFavoriteType();
167 int32_t burstType = searchCondition.GetBurstType();
168 bool hasLowQualityImage = this->HasLowQualityImage();
169 int32_t hasLowQualityImageFlag = hasLowQualityImage == true ? 1 : 0;
170 int32_t shouldIncludeSdFlag = this->shouldIncludeSd_ == true ? 1 : 0;
171 std::vector<NativeRdb::ValueObject> params = {hasLowQualityImageFlag,
172 shouldIncludeSdFlag,
173 mediaType,
174 mediaType,
175 hiddenType,
176 hiddenType,
177 hiddenType,
178 trashedType,
179 trashedType,
180 trashedType,
181 cloudType,
182 cloudType,
183 cloudType,
184 favoriteType,
185 favoriteType,
186 favoriteType,
187 burstType,
188 burstType,
189 burstType};
190 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_GALLERY_MEDIA_QUERY_COUNT, params);
191 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
192 return 0;
193 }
194 return GetInt32Val("count", resultSet);
195 }
196
QueryGalleryCloneCount()197 int32_t GalleryMediaCountStatistic::QueryGalleryCloneCount()
198 {
199 static string QUERY_GALLERY_CLONE_COUNT =
200 string("SELECT count(1) AS count FROM gallery_media WHERE local_media_id = -3 AND _size > 0 ") +
201 "AND (storage_id IN (0, 65537)) AND relative_bucket_id NOT IN ( " +
202 "SELECT DISTINCT relative_bucket_id FROM garbage_album WHERE type = 1)";
203 return BackupDatabaseUtils::QueryInt(this->galleryRdb_, QUERY_GALLERY_CLONE_COUNT, CUSTOM_COUNT);
204 }
205
206 /**
207 * @brief Get the row count of gallery_media storage in SD card.
208 * @param mediaType - 0 all, 1 picture, 3 video
209 */
QueryGallerySdCardCount(SearchCondition searchCondition)210 int32_t GalleryMediaCountStatistic::QueryGallerySdCardCount(SearchCondition searchCondition)
211 {
212 if (this->galleryRdb_ == nullptr) {
213 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
214 return 0;
215 }
216 int32_t mediaType = searchCondition.GetMediaType();
217 int32_t hiddenType = searchCondition.GetHiddenType();
218 int32_t trashedType = searchCondition.GetTrashedType();
219 int32_t cloudType = searchCondition.GetCloudType();
220 int32_t favoriteType = searchCondition.GetFavoriteType();
221 int32_t burstType = searchCondition.GetBurstType();
222 std::vector<NativeRdb::ValueObject> params = {mediaType,
223 mediaType,
224 hiddenType,
225 hiddenType,
226 hiddenType,
227 trashedType,
228 trashedType,
229 trashedType,
230 cloudType,
231 cloudType,
232 cloudType,
233 favoriteType,
234 favoriteType,
235 favoriteType,
236 burstType,
237 burstType,
238 burstType};
239 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_GALLERY_SD_CARD_COUNT, params);
240 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
241 return 0;
242 }
243 return GetInt32Val("count", resultSet);
244 }
245
246 /**
247 * @brief Get the row count of gallery_media.
248 * @param searchType - 0 all, 1 cloud
249 * @param mediaType - 0 all, 1 picture, 3 video
250 */
QueryAlbumAllVideoCount(SearchCondition searchCondition)251 int32_t GalleryMediaCountStatistic::QueryAlbumAllVideoCount(SearchCondition searchCondition)
252 {
253 if (this->galleryRdb_ == nullptr) {
254 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
255 return 0;
256 }
257 int32_t mediaType = searchCondition.GetMediaType();
258 int32_t hiddenType = searchCondition.GetHiddenType();
259 int32_t trashedType = searchCondition.GetTrashedType();
260 int32_t cloudType = searchCondition.GetCloudType();
261 int32_t favoriteType = searchCondition.GetFavoriteType();
262 int32_t burstType = searchCondition.GetBurstType();
263 std::vector<NativeRdb::ValueObject> params = {mediaType,
264 mediaType,
265 hiddenType,
266 hiddenType,
267 hiddenType,
268 trashedType,
269 trashedType,
270 trashedType,
271 cloudType,
272 cloudType,
273 cloudType,
274 favoriteType,
275 favoriteType,
276 favoriteType,
277 burstType,
278 burstType,
279 burstType};
280 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_GALLERY_MEDIA_ALL_VIDEO_COUNT, params);
281 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
282 return 0;
283 }
284 return GetInt32Val("count", resultSet);
285 }
286
287 /**
288 * @brief Get the row count of gallery_media.
289 * @param searchType - 0 all, 1 cloud
290 * @param mediaType - 0 all, 1 picture, 3 video
291 */
QueryLiveCount(int32_t searchType,int32_t mediaType)292 int32_t GalleryMediaCountStatistic::QueryLiveCount(int32_t searchType, int32_t mediaType)
293 {
294 if (this->galleryRdb_ == nullptr) {
295 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
296 return 0;
297 }
298 std::vector<NativeRdb::ValueObject> params = {searchType, mediaType, mediaType};
299 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_LIVE_COUNT, params);
300 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
301 return 0;
302 }
303 return GetInt32Val("count", resultSet);
304 }
305
306 /**
307 * @brief Get the row count of gallery_media.
308 * @param searchType - 0 all, 1 cloud
309 * @param mediaType - 0 all, 1 picture, 3 video
310 */
QueryTempCount(int32_t searchType,int32_t mediaType)311 int32_t GalleryMediaCountStatistic::QueryTempCount(int32_t searchType, int32_t mediaType)
312 {
313 if (this->galleryRdb_ == nullptr) {
314 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
315 return 0;
316 }
317 std::vector<NativeRdb::ValueObject> params = {searchType, mediaType, mediaType};
318 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_TEMP_COUNT, params);
319 if (resultSet == nullptr || resultSet->GoToFirstRow() != NativeRdb::E_OK) {
320 return 0;
321 }
322 return GetInt32Val("count", resultSet);
323 }
324
325 /**
326 * @brief Get the row count of gallery_media.
327 * @param searchType - 0 all, 1 cloud
328 * @param mediaType - 0 all, 1 picture, 3 video
329 */
QueryAlbumCountByName(const std::string & albumName,SearchCondition searchCondition)330 std::vector<AlbumStatisticInfo> GalleryMediaCountStatistic::QueryAlbumCountByName(
331 const std::string &albumName, SearchCondition searchCondition)
332 {
333 if (this->galleryRdb_ == nullptr) {
334 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
335 return {};
336 }
337 int32_t mediaType = searchCondition.GetMediaType();
338 int32_t hiddenType = searchCondition.GetHiddenType();
339 int32_t trashedType = searchCondition.GetTrashedType();
340 int32_t cloudType = searchCondition.GetCloudType();
341 int32_t favoriteType = searchCondition.GetFavoriteType();
342 int32_t burstType = searchCondition.GetBurstType();
343 std::vector<NativeRdb::ValueObject> params = {albumName,
344 mediaType,
345 mediaType,
346 hiddenType,
347 hiddenType,
348 hiddenType,
349 trashedType,
350 trashedType,
351 trashedType,
352 cloudType,
353 cloudType,
354 cloudType,
355 favoriteType,
356 favoriteType,
357 favoriteType,
358 burstType,
359 burstType,
360 burstType};
361 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_ALBUM_COUNT_BY_NAME, params);
362 if (resultSet == nullptr) {
363 return {};
364 }
365 std::vector<AlbumStatisticInfo> infoList;
366 while (resultSet->GoToNextRow() == NativeRdb::E_OK) {
367 AlbumStatisticInfo info;
368 info.count = GetInt32Val("count", resultSet);
369 info.lPath = GetStringVal("lPath", resultSet);
370 info.albumName = GetStringVal("albumName", resultSet);
371 infoList.emplace_back(info);
372 }
373 return infoList;
374 }
375
376 /**
377 * @brief Get the row count of gallery_media.
378 * @param searchType - 0 all, 1 cloud
379 * @param mediaType - 0 all, 1 picture, 3 video
380 */
QueryAlbumCountByLPath(const std::string & lPath,SearchCondition searchCondition)381 std::vector<AlbumStatisticInfo> GalleryMediaCountStatistic::QueryAlbumCountByLPath(
382 const std::string &lPath, SearchCondition searchCondition)
383 {
384 if (this->galleryRdb_ == nullptr) {
385 MEDIA_ERR_LOG("Media_Restore: galleryRdb_ is null.");
386 return {};
387 }
388 int32_t mediaType = searchCondition.GetMediaType();
389 int32_t hiddenType = searchCondition.GetHiddenType();
390 int32_t trashedType = searchCondition.GetTrashedType();
391 int32_t cloudType = searchCondition.GetCloudType();
392 int32_t favoriteType = searchCondition.GetFavoriteType();
393 int32_t burstType = searchCondition.GetBurstType();
394 std::vector<NativeRdb::ValueObject> params = {lPath,
395 mediaType,
396 mediaType,
397 hiddenType,
398 hiddenType,
399 hiddenType,
400 trashedType,
401 trashedType,
402 trashedType,
403 cloudType,
404 cloudType,
405 cloudType,
406 favoriteType,
407 favoriteType,
408 favoriteType,
409 burstType,
410 burstType,
411 burstType};
412 auto resultSet = this->galleryRdb_->QuerySql(this->SQL_QUERY_ALBUM_COUNT_BY_LPATH, params);
413 if (resultSet == nullptr) {
414 return {};
415 }
416 std::vector<AlbumStatisticInfo> infoList;
417 while (resultSet->GoToNextRow() == NativeRdb::E_OK) {
418 AlbumStatisticInfo info;
419 info.count = GetInt32Val("count", resultSet);
420 info.albumName = GetStringVal("albumName", resultSet);
421 info.lPath = GetStringVal("lPath", resultSet);
422 infoList.emplace_back(info);
423 }
424 return infoList;
425 }
426
HasLowQualityImage()427 bool GalleryMediaCountStatistic::HasLowQualityImage()
428 {
429 std::string sql = "SELECT count(1) AS count FROM gallery_media WHERE (local_media_id != -1) AND \
430 (storage_id IN (0, 65537)) AND relative_bucket_id NOT IN (SELECT DISTINCT relative_bucket_id FROM \
431 garbage_album WHERE type = 1) AND _size = 0 AND photo_quality = 0";
432 int count = BackupDatabaseUtils::QueryInt(galleryRdb_, sql, CUSTOM_COUNT);
433 MEDIA_INFO_LOG("HasLowQualityImage count:%{public}d", count);
434 return count > 0;
435 }
436
QueryGalleryAppTwinDataCount()437 int32_t GalleryMediaCountStatistic::QueryGalleryAppTwinDataCount()
438 {
439 std::string sql =
440 "SELECT count(1) AS count FROM gallery_media WHERE _data LIKE '/storage/emulated/%' AND "
441 "CAST (substr(_data, length('/storage/emulated/') + 1, 3) AS INTEGER) BETWEEN 128 AND 147 AND _size > 0";
442 return BackupDatabaseUtils::QueryInt(galleryRdb_, sql, CUSTOM_COUNT);
443 }
444
GetAllStatInfo()445 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllStatInfo()
446 {
447 AlbumMediaStatisticInfo info;
448 info.sceneCode = this->sceneCode_;
449 info.taskId = this->taskId_;
450 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
451 // build the statistic info.
452 info.totalCount = this->QueryGalleryAllCount(SearchCondition());
453 info.imageCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
454 info.videoCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
455 info.hiddenCount = this->QueryGalleryAllCount(SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
456 info.trashedCount = this->QueryGalleryAllCount(SearchCondition().SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
457 info.cloudCount = this->QueryGalleryAllCount(SearchCondition().SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
458 info.favoriteCount = this->QueryGalleryAllCount(SearchCondition().SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
459 info.burstTotalCount = this->QueryGalleryAllCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_ALL));
460 info.burstCoverCount = this->QueryGalleryAllCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_COVER));
461 // build the album name.
462 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
463 int64_t costTime = endTime - startTime;
464 std::string albumName = "ALL";
465 std::string lPath = "";
466 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
467 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
468 info.albumName = AlbumNameInfo()
469 .SetAlbumName(albumName)
470 .SetLPath(lPath)
471 .SetCostTime(costTime)
472 .SetPeriod(period)
473 .SetDbType(dbType)
474 .ToString();
475 return info;
476 }
477
GetAllImageStatInfo()478 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllImageStatInfo()
479 {
480 AlbumMediaStatisticInfo info;
481 info.sceneCode = this->sceneCode_;
482 info.taskId = this->taskId_;
483 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
484 // build the statistic info.
485 info.totalCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
486 info.imageCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
487 info.videoCount = 0;
488 info.hiddenCount = this->QueryGalleryAllCount(
489 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
490 info.trashedCount = this->QueryGalleryAllCount(
491 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
492 info.cloudCount = this->QueryGalleryAllCount(
493 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
494 info.favoriteCount = this->QueryGalleryAllCount(
495 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
496 info.burstTotalCount = this->QueryGalleryAllCount(
497 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetBurstType(DUAL_BURST_TYPE_ALL));
498 info.burstCoverCount = this->QueryGalleryAllCount(
499 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetBurstType(DUAL_BURST_TYPE_COVER));
500 // build the album name.
501 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
502 int64_t costTime = endTime - startTime;
503 std::string albumName = "ALL_IMAGE";
504 std::string lPath = "";
505 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
506 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
507 info.albumName = AlbumNameInfo()
508 .SetAlbumName(albumName)
509 .SetLPath(lPath)
510 .SetCostTime(costTime)
511 .SetPeriod(period)
512 .SetDbType(dbType)
513 .ToString();
514 return info;
515 }
516
GetAllVideoStatInfo()517 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllVideoStatInfo()
518 {
519 AlbumMediaStatisticInfo info;
520 info.sceneCode = this->sceneCode_;
521 info.taskId = this->taskId_;
522 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
523 // build the statistic info.
524 info.totalCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
525 info.imageCount = 0;
526 info.videoCount = this->QueryGalleryAllCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
527 info.hiddenCount = this->QueryGalleryAllCount(
528 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
529 info.trashedCount = this->QueryGalleryAllCount(
530 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
531 info.cloudCount = this->QueryGalleryAllCount(
532 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
533 info.favoriteCount = this->QueryGalleryAllCount(
534 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
535 info.burstTotalCount = 0;
536 info.burstCoverCount = 0;
537 // build the album name.
538 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
539 int64_t costTime = endTime - startTime;
540 std::string albumName = "ALL_VIDEO";
541 std::string lPath = "";
542 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
543 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
544 info.albumName = AlbumNameInfo()
545 .SetAlbumName(albumName)
546 .SetLPath(lPath)
547 .SetCostTime(costTime)
548 .SetPeriod(period)
549 .SetDbType(dbType)
550 .ToString();
551 return info;
552 }
553
GetAllRestoreStatInfo()554 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllRestoreStatInfo()
555 {
556 AlbumMediaStatisticInfo info;
557 info.sceneCode = this->sceneCode_;
558 info.taskId = this->taskId_;
559 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
560 // build the statistic info.
561 info.totalCount = this->GetGalleryMediaAllRestoreCount(SearchCondition());
562 info.imageCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
563 info.videoCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
564 info.hiddenCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
565 info.trashedCount =
566 this->GetGalleryMediaAllRestoreCount(SearchCondition().SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
567 info.cloudCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
568 info.favoriteCount =
569 this->GetGalleryMediaAllRestoreCount(SearchCondition().SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
570 info.burstTotalCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_ALL));
571 info.burstCoverCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_COVER));
572 // build the album name.
573 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
574 int64_t costTime = endTime - startTime;
575 std::string albumName = "ALL_RESTORE";
576 std::string lPath = "";
577 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
578 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
579 info.albumName = AlbumNameInfo()
580 .SetAlbumName(albumName)
581 .SetLPath(lPath)
582 .SetCostTime(costTime)
583 .SetPeriod(period)
584 .SetDbType(dbType)
585 .ToString();
586 return info;
587 }
588
GetAllRestoreImageStatInfo()589 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllRestoreImageStatInfo()
590 {
591 AlbumMediaStatisticInfo info;
592 info.sceneCode = this->sceneCode_;
593 info.taskId = this->taskId_;
594 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
595 // build the statistic info.
596 info.totalCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
597 info.imageCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
598 info.videoCount = 0;
599 info.hiddenCount = this->GetGalleryMediaAllRestoreCount(
600 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
601 info.trashedCount = this->GetGalleryMediaAllRestoreCount(
602 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
603 info.cloudCount = this->GetGalleryMediaAllRestoreCount(
604 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
605 info.favoriteCount = this->GetGalleryMediaAllRestoreCount(
606 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
607 info.burstTotalCount = this->GetGalleryMediaAllRestoreCount(
608 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetBurstType(DUAL_BURST_TYPE_ALL));
609 info.burstCoverCount = this->GetGalleryMediaAllRestoreCount(
610 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE).SetBurstType(DUAL_BURST_TYPE_COVER));
611 // build the album name.
612 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
613 int64_t costTime = endTime - startTime;
614 std::string albumName = "ALL_RESTORE_IMAGE";
615 std::string lPath = "";
616 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
617 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
618 info.albumName = AlbumNameInfo()
619 .SetAlbumName(albumName)
620 .SetLPath(lPath)
621 .SetCostTime(costTime)
622 .SetPeriod(period)
623 .SetDbType(dbType)
624 .ToString();
625 return info;
626 }
627
GetAllRestoreVideoStatInfo()628 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAllRestoreVideoStatInfo()
629 {
630 AlbumMediaStatisticInfo info;
631 info.sceneCode = this->sceneCode_;
632 info.taskId = this->taskId_;
633 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
634 // build the statistic info.
635 info.totalCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
636 info.imageCount = 0;
637 info.videoCount = this->GetGalleryMediaAllRestoreCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
638 info.hiddenCount = this->GetGalleryMediaAllRestoreCount(
639 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
640 info.trashedCount = this->GetGalleryMediaAllRestoreCount(
641 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
642 info.cloudCount = this->GetGalleryMediaAllRestoreCount(
643 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
644 info.favoriteCount = this->GetGalleryMediaAllRestoreCount(
645 SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
646 info.burstTotalCount = 0;
647 info.burstCoverCount = 0;
648 // build the album name.
649 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
650 int64_t costTime = endTime - startTime;
651 std::string albumName = "ALL_RESTORE_VIDEO";
652 std::string lPath = "";
653 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
654 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
655 info.albumName = AlbumNameInfo()
656 .SetAlbumName(albumName)
657 .SetLPath(lPath)
658 .SetCostTime(costTime)
659 .SetPeriod(period)
660 .SetDbType(dbType)
661 .ToString();
662 return info;
663 }
664
GetSdCardStatInfo()665 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetSdCardStatInfo()
666 {
667 AlbumMediaStatisticInfo info;
668 info.sceneCode = this->sceneCode_;
669 info.taskId = this->taskId_;
670 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
671 // build the statistic info.
672 info.totalCount = this->QueryGallerySdCardCount(SearchCondition());
673 info.imageCount = this->QueryGallerySdCardCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
674 info.videoCount = this->QueryGallerySdCardCount(SearchCondition().SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
675 info.hiddenCount = this->QueryGallerySdCardCount(SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_HIDDEN));
676 info.trashedCount = this->QueryGallerySdCardCount(SearchCondition().SetTrashedType(DUAL_TRASHED_TYPE_TRASHED));
677 info.cloudCount = this->QueryGallerySdCardCount(SearchCondition().SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
678 info.favoriteCount = this->QueryGallerySdCardCount(SearchCondition().SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
679 info.burstTotalCount = this->QueryGallerySdCardCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_ALL));
680 info.burstCoverCount = this->QueryGallerySdCardCount(SearchCondition().SetBurstType(DUAL_BURST_TYPE_COVER));
681 // build the album name.
682 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
683 int64_t costTime = endTime - startTime;
684 std::string albumName = "SD_CARD";
685 std::string lPath = "";
686 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
687 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
688 info.albumName = AlbumNameInfo()
689 .SetAlbumName(albumName)
690 .SetLPath(lPath)
691 .SetCostTime(costTime)
692 .SetPeriod(period)
693 .SetDbType(dbType)
694 .ToString();
695 return info;
696 }
697
GetDuplicateStatInfo()698 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetDuplicateStatInfo()
699 {
700 int32_t duplicateDataCount;
701 int32_t duplicateDataTotal;
702 BackupDatabaseUtils::QueryGalleryDuplicateDataCount(this->galleryRdb_, duplicateDataCount, duplicateDataTotal);
703 AlbumMediaStatisticInfo info;
704 info.sceneCode = this->sceneCode_;
705 info.taskId = this->taskId_;
706 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
707 // build the statistic info.
708 info.totalCount = duplicateDataTotal;
709 // build the album name.
710 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
711 int64_t costTime = endTime - startTime;
712 std::string albumName = "DUPLICATE";
713 std::string lPath = "";
714 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
715 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
716 info.albumName = AlbumNameInfo()
717 .SetAlbumName(albumName)
718 .SetLPath(lPath)
719 .SetCostTime(costTime)
720 .SetPeriod(period)
721 .SetDbType(dbType)
722 .ToString();
723 return info;
724 }
725
GetAppTwinStatInfo()726 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetAppTwinStatInfo()
727 {
728 AlbumMediaStatisticInfo info;
729 info.sceneCode = this->sceneCode_;
730 info.taskId = this->taskId_;
731 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
732 // build the statistic info.
733 info.totalCount = this->QueryGalleryAppTwinDataCount();
734 // build the album name.
735 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
736 int64_t costTime = endTime - startTime;
737 std::string albumName = "APP_TWIN";
738 std::string lPath = "";
739 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
740 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
741 info.albumName = AlbumNameInfo()
742 .SetAlbumName(albumName)
743 .SetLPath(lPath)
744 .SetCostTime(costTime)
745 .SetPeriod(period)
746 .SetDbType(dbType)
747 .ToString();
748 return info;
749 }
750
GetImageAlbumInfo()751 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetImageAlbumInfo()
752 {
753 AlbumMediaStatisticInfo info;
754 info.sceneCode = this->sceneCode_;
755 info.taskId = this->taskId_;
756 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
757 // build the statistic info.
758 SearchCondition defaultCondition =
759 SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN).SetTrashedType(DUAL_TRASHED_TYPE_NOT_TRASHED);
760 info.totalCount = this->QueryAlbumGalleryCount(SearchCondition(defaultCondition));
761 info.imageCount =
762 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
763 info.videoCount =
764 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
765 info.hiddenCount = 0;
766 info.trashedCount = 0;
767 info.cloudCount =
768 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
769 info.favoriteCount =
770 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
771 info.burstTotalCount =
772 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_ALL));
773 info.burstCoverCount =
774 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_COVER));
775 // build the album name.
776 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
777 int64_t costTime = endTime - startTime;
778 std::string albumName = "所有照片";
779 std::string lPath = "";
780 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
781 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
782 info.albumName = AlbumNameInfo()
783 .SetAlbumName(albumName)
784 .SetLPath(lPath)
785 .SetCostTime(costTime)
786 .SetPeriod(period)
787 .SetDbType(dbType)
788 .ToString();
789 return info;
790 }
791
GetVideoAlbumInfo()792 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetVideoAlbumInfo()
793 {
794 AlbumMediaStatisticInfo info;
795 info.sceneCode = this->sceneCode_;
796 info.taskId = this->taskId_;
797 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
798 // build the statistic info.
799 SearchCondition defaultCondition = SearchCondition()
800 .SetMediaType(DUAL_MEDIA_TYPE_VIDEO)
801 .SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN)
802 .SetTrashedType(DUAL_TRASHED_TYPE_NOT_TRASHED);
803 info.totalCount = this->QueryAlbumAllVideoCount(SearchCondition(defaultCondition));
804 info.imageCount = 0;
805 info.videoCount = this->QueryAlbumAllVideoCount(SearchCondition(defaultCondition));
806 info.hiddenCount = 0;
807 info.trashedCount = 0;
808 info.cloudCount =
809 this->QueryAlbumAllVideoCount(SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
810 info.favoriteCount =
811 this->QueryAlbumAllVideoCount(SearchCondition(defaultCondition).SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE));
812 info.burstTotalCount = 0;
813 info.burstCoverCount = 0;
814 // build the album name.
815 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
816 int64_t costTime = endTime - startTime;
817 std::string albumName = "视频";
818 std::string lPath = "";
819 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
820 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
821 info.albumName = AlbumNameInfo()
822 .SetAlbumName(albumName)
823 .SetLPath(lPath)
824 .SetCostTime(costTime)
825 .SetPeriod(period)
826 .SetDbType(dbType)
827 .ToString();
828 return info;
829 }
830
GetFavoriteAlbumStatInfo()831 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetFavoriteAlbumStatInfo()
832 {
833 AlbumMediaStatisticInfo info;
834 info.sceneCode = this->sceneCode_;
835 info.taskId = this->taskId_;
836 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
837 // build the statistic info.
838 SearchCondition defaultCondition = SearchCondition()
839 .SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN)
840 .SetTrashedType(DUAL_TRASHED_TYPE_NOT_TRASHED)
841 .SetFavoriteType(DUAL_FAVORITE_TYPE_FAVORITE);
842 info.totalCount = this->QueryAlbumGalleryCount(SearchCondition(defaultCondition));
843 info.imageCount =
844 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
845 info.videoCount =
846 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
847 info.hiddenCount = 0;
848 info.trashedCount = 0;
849 info.cloudCount =
850 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
851 info.favoriteCount = this->QueryAlbumGalleryCount(SearchCondition(defaultCondition));
852 info.burstTotalCount =
853 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_ALL));
854 info.burstCoverCount =
855 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_COVER));
856 // build the album name.
857 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
858 int64_t costTime = endTime - startTime;
859 std::string albumName = "收藏";
860 std::string lPath = "";
861 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
862 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
863 info.albumName = AlbumNameInfo()
864 .SetAlbumName(albumName)
865 .SetLPath(lPath)
866 .SetCostTime(costTime)
867 .SetPeriod(period)
868 .SetDbType(dbType)
869 .ToString();
870 return info;
871 }
872
GetTrashedAlbumStatInfo()873 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetTrashedAlbumStatInfo()
874 {
875 AlbumMediaStatisticInfo info;
876 info.sceneCode = this->sceneCode_;
877 info.taskId = this->taskId_;
878 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
879 // build the statistic info.
880 SearchCondition defaultCondition =
881 SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN).SetTrashedType(DUAL_TRASHED_TYPE_TRASHED);
882 info.totalCount = this->QueryAlbumGalleryCount(SearchCondition(defaultCondition));
883 info.imageCount =
884 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
885 info.videoCount =
886 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
887 info.hiddenCount = 0;
888 info.trashedCount = this->QueryAlbumGalleryCount(SearchCondition(defaultCondition));
889 info.cloudCount =
890 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
891 info.favoriteCount = 0;
892 info.burstTotalCount =
893 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_ALL));
894 info.burstCoverCount =
895 this->QueryAlbumGalleryCount(SearchCondition(defaultCondition).SetBurstType(DUAL_BURST_TYPE_COVER));
896 // build the album name.
897 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
898 int64_t costTime = endTime - startTime;
899 std::string albumName = "回收站";
900 std::string lPath = "";
901 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
902 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
903 info.albumName = AlbumNameInfo()
904 .SetAlbumName(albumName)
905 .SetLPath(lPath)
906 .SetCostTime(costTime)
907 .SetPeriod(period)
908 .SetDbType(dbType)
909 .ToString();
910 return info;
911 }
912
GetAlbumInfoByName(const std::string & albumName)913 std::vector<AlbumMediaStatisticInfo> GalleryMediaCountStatistic::GetAlbumInfoByName(const std::string &albumName)
914 {
915 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
916 // build the statistic info.
917 SearchCondition defaultCondition =
918 SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN).SetTrashedType(DUAL_TRASHED_TYPE_NOT_TRASHED);
919 std::vector<AlbumStatisticInfo> totalCountInfoList =
920 this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition));
921 std::vector<AlbumStatisticInfo> imageCountInfoList =
922 this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
923 std::vector<AlbumStatisticInfo> videoCountInfoList =
924 this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
925 std::vector<AlbumStatisticInfo> cloudCountInfoList =
926 this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
927 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
928 int64_t costTime = endTime - startTime;
929 // Parse the statistic info.
930 std::unordered_map<std::string, AlbumMediaStatisticInfo> albumInfoMap;
931 StatisticProcessor()
932 .ParseTotalCount(albumInfoMap, totalCountInfoList)
933 .ParseImageCount(albumInfoMap, imageCountInfoList)
934 .ParseVideoCount(albumInfoMap, videoCountInfoList)
935 .ParseCloudCount(albumInfoMap, cloudCountInfoList);
936 std::vector<AlbumMediaStatisticInfo> albumInfoList;
937 for (const auto &iter : albumInfoMap) {
938 AlbumMediaStatisticInfo info = iter.second;
939 info.sceneCode = this->sceneCode_;
940 info.taskId = this->taskId_;
941 info.albumName = AlbumNameInfo()
942 .SetAlbumName(info.albumName)
943 .SetLPath(info.lPath)
944 .SetCostTime(costTime)
945 .SetPeriod(0) // 0 - BEFORE, 1 - AFTER
946 .SetDbType(0) // 0 - GALLERY, 1 - MEDIA
947 .ToString();
948 albumInfoList.emplace_back(info);
949 }
950 return albumInfoList;
951 }
952
GetAlbumInfoByLPath(const std::string & lPath)953 std::vector<AlbumMediaStatisticInfo> GalleryMediaCountStatistic::GetAlbumInfoByLPath(const std::string &lPath)
954 {
955 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
956 // build the statistic info.
957 SearchCondition defaultCondition =
958 SearchCondition().SetHiddenType(DUAL_HIDDEN_TYPE_NOT_HIDDEN).SetTrashedType(DUAL_TRASHED_TYPE_NOT_TRASHED);
959 std::vector<AlbumStatisticInfo> totalCountInfoList =
960 this->QueryAlbumCountByLPath(lPath, SearchCondition(defaultCondition));
961 std::vector<AlbumStatisticInfo> imageCountInfoList =
962 this->QueryAlbumCountByLPath(lPath, SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_IMAGE));
963 std::vector<AlbumStatisticInfo> videoCountInfoList =
964 this->QueryAlbumCountByLPath(lPath, SearchCondition(defaultCondition).SetMediaType(DUAL_MEDIA_TYPE_VIDEO));
965 std::vector<AlbumStatisticInfo> cloudCountInfoList =
966 this->QueryAlbumCountByLPath(lPath, SearchCondition(defaultCondition).SetCloudType(DUAL_CLOUD_TYPE_CLOUD));
967 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
968 int64_t costTime = endTime - startTime;
969 // Parse the statistic info.
970 std::unordered_map<std::string, AlbumMediaStatisticInfo> albumInfoMap;
971 StatisticProcessor()
972 .ParseTotalCount(albumInfoMap, totalCountInfoList)
973 .ParseImageCount(albumInfoMap, imageCountInfoList)
974 .ParseVideoCount(albumInfoMap, videoCountInfoList)
975 .ParseCloudCount(albumInfoMap, cloudCountInfoList);
976 std::vector<AlbumMediaStatisticInfo> albumInfoList;
977 for (const auto &iter : albumInfoMap) {
978 AlbumMediaStatisticInfo info = iter.second;
979 info.sceneCode = this->sceneCode_;
980 info.taskId = this->taskId_;
981 info.albumName = AlbumNameInfo()
982 .SetAlbumName(info.albumName)
983 .SetLPath(info.lPath)
984 .SetCostTime(costTime)
985 .SetPeriod(0) // 0 - BEFORE, 1 - AFTER
986 .SetDbType(0) // 0 - GALLERY, 1 - MEDIA
987 .ToString();
988 albumInfoList.emplace_back(info);
989 }
990 return albumInfoList;
991 }
992
GetGalleryAlbumCountInfo()993 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetGalleryAlbumCountInfo()
994 {
995 AlbumMediaStatisticInfo info;
996 info.sceneCode = this->sceneCode_;
997 info.taskId = this->taskId_;
998 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
999 // build the statistic info.
1000 info.totalCount = this->GetCount(this->SQL_QUERY_GALLERY_ALBUM_COUNT);
1001 // build the album name.
1002 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
1003 int64_t costTime = endTime - startTime;
1004 std::string albumName = "相册数量";
1005 std::string lPath = "";
1006 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
1007 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
1008 info.albumName = AlbumNameInfo()
1009 .SetAlbumName(albumName)
1010 .SetLPath(lPath)
1011 .SetCostTime(costTime)
1012 .SetPeriod(period)
1013 .SetDbType(dbType)
1014 .ToString();
1015 return info;
1016 }
1017
GetLiveStatInfo()1018 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetLiveStatInfo()
1019 {
1020 AlbumMediaStatisticInfo info;
1021 info.sceneCode = this->sceneCode_;
1022 info.taskId = this->taskId_;
1023 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
1024 // build the statistic info.
1025 info.totalCount = this->QueryLiveCount(DUAL_SEARCH_TYPE_ALL, DUAL_MEDIA_TYPE_ALL);
1026 info.cloudCount = this->QueryLiveCount(DUAL_SEARCH_TYPE_CLOUD, DUAL_MEDIA_TYPE_ALL);
1027 // build the album name.
1028 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
1029 int64_t costTime = endTime - startTime;
1030 std::string albumName = "动态照片";
1031 std::string lPath = "";
1032 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
1033 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
1034 info.albumName = AlbumNameInfo()
1035 .SetAlbumName(albumName)
1036 .SetLPath(lPath)
1037 .SetCostTime(costTime)
1038 .SetPeriod(period)
1039 .SetDbType(dbType)
1040 .ToString();
1041 return info;
1042 }
1043
GetTempInfo()1044 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetTempInfo()
1045 {
1046 AlbumMediaStatisticInfo info;
1047 info.sceneCode = this->sceneCode_;
1048 info.taskId = this->taskId_;
1049 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
1050 // build the statistic info.
1051 info.totalCount = this->QueryTempCount(DUAL_SEARCH_TYPE_ALL, DUAL_MEDIA_TYPE_ALL);
1052 info.imageCount = this->QueryTempCount(DUAL_SEARCH_TYPE_ALL, DUAL_MEDIA_TYPE_IMAGE);
1053 info.videoCount = this->QueryTempCount(DUAL_SEARCH_TYPE_ALL, DUAL_MEDIA_TYPE_VIDEO);
1054 info.cloudCount = this->QueryTempCount(DUAL_SEARCH_TYPE_CLOUD, DUAL_MEDIA_TYPE_ALL);
1055 // build the album name.
1056 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
1057 int64_t costTime = endTime - startTime;
1058 std::string albumName = "应用缓存文件";
1059 std::string lPath = "";
1060 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
1061 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
1062 info.albumName = AlbumNameInfo()
1063 .SetAlbumName(albumName)
1064 .SetLPath(lPath)
1065 .SetCostTime(costTime)
1066 .SetPeriod(period)
1067 .SetDbType(dbType)
1068 .ToString();
1069 return info;
1070 }
1071
GetNotSyncInfo()1072 AlbumMediaStatisticInfo GalleryMediaCountStatistic::GetNotSyncInfo()
1073 {
1074 AlbumMediaStatisticInfo info;
1075 info.sceneCode = this->sceneCode_;
1076 info.taskId = this->taskId_;
1077 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
1078 // build the statistic info.
1079 info.totalCount = this->GetCount(SQL_QUERY_NOT_SYNC_COUNT);
1080 // build the album name.
1081 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
1082 int64_t costTime = endTime - startTime;
1083 std::string albumName = "媒体库未同步";
1084 std::string lPath = "";
1085 int32_t period = 0; // 0 - BEFORE, 1 - AFTER
1086 int32_t dbType = 0; // 0 - GALLERY, 1 - MEDIA
1087 info.albumName = AlbumNameInfo()
1088 .SetAlbumName(albumName)
1089 .SetLPath(lPath)
1090 .SetCostTime(costTime)
1091 .SetPeriod(period)
1092 .SetDbType(dbType)
1093 .ToString();
1094 return info;
1095 }
1096 } // namespace OHOS::Media