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