• 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 "photos_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> PhotosCountStatistic::Load()
26 {
27     if (this->mediaLibraryRdb_ == nullptr) {
28         MEDIA_ERR_LOG("mediaLibraryRdb_ 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->GetLiveStatInfo(),
41         this->GetGalleryAlbumCountInfo(),
42         this->GetGalleryDeletedAlbumCountInfo(),
43         // statistic info.
44         this->GetImageAlbumInfo(),
45         this->GetVideoAlbumInfo(),
46         // folder info.
47         this->GetFavoriteAlbumStatInfo(),
48         this->GetTrashedAlbumStatInfo(),
49         this->GetHiddenAlbumStatInfo(),
50     };
51     // key album of album_plugin.
52     std::vector<AlbumMediaStatisticInfo> cameraAlbumList = this->GetAlbumInfoByName("相机");
53     infoList.insert(infoList.end(), cameraAlbumList.begin(), cameraAlbumList.end());
54     std::vector<AlbumMediaStatisticInfo> screenShotAlbumList = this->GetAlbumInfoByName("截图");
55     infoList.insert(infoList.end(), screenShotAlbumList.begin(), screenShotAlbumList.end());
56     std::vector<AlbumMediaStatisticInfo> screenRecordAlbumList = this->GetAlbumInfoByName("屏幕录制");
57     infoList.insert(infoList.end(), screenRecordAlbumList.begin(), screenRecordAlbumList.end());
58     std::vector<AlbumMediaStatisticInfo> weiXinAlbumList = this->GetAlbumInfoByName("微信");
59     infoList.insert(infoList.end(), weiXinAlbumList.begin(), weiXinAlbumList.end());
60     std::vector<AlbumMediaStatisticInfo> weiboAlbumList = this->GetAlbumInfoByName("微博");
61     infoList.insert(infoList.end(), weiboAlbumList.begin(), weiboAlbumList.end());
62     std::vector<AlbumMediaStatisticInfo> shareAlbumList = this->GetAlbumInfoByName("华为分享");
63     infoList.insert(infoList.end(), shareAlbumList.begin(), shareAlbumList.end());
64     std::vector<AlbumMediaStatisticInfo> otherAlbumList = this->GetAlbumInfoByName("其它");
65     infoList.insert(infoList.end(), otherAlbumList.begin(), otherAlbumList.end());
66     return infoList;
67 }
68 
GetCount(const std::string & query,const std::vector<NativeRdb::ValueObject> & args)69 int32_t PhotosCountStatistic::GetCount(const std::string &query, const std::vector<NativeRdb::ValueObject> &args)
70 {
71     return BackupDatabaseUtils::QueryInt(this->mediaLibraryRdb_, query, CUSTOM_COUNT, args);
72 }
73 
74 /**
75  * @brief Get the row count of media_library storage in SD card.
76  * @param mediaType - 0 all, 1 picture, 3 video
77  */
QueryTotalCount(SearchCondition searchCondition)78 int32_t PhotosCountStatistic::QueryTotalCount(SearchCondition searchCondition)
79 {
80     CHECK_AND_RETURN_RET_LOG(this->mediaLibraryRdb_ != nullptr, 0, "Media_Restore: mediaLibraryRdb_ is null.");
81     int32_t mediaType = searchCondition.GetMediaType();
82     int32_t hiddenType = searchCondition.GetHiddenType();
83     int32_t trashedType = searchCondition.GetTrashedType();
84     int32_t cloudType = searchCondition.GetCloudType();
85     int32_t favoriteType = searchCondition.GetFavoriteType();
86     int32_t burstType = searchCondition.GetBurstType();
87     std::vector<NativeRdb::ValueObject> params = {mediaType,
88         mediaType,
89         hiddenType,
90         hiddenType,
91         hiddenType,
92         trashedType,
93         trashedType,
94         trashedType,
95         cloudType,
96         cloudType,
97         cloudType,
98         favoriteType,
99         favoriteType,
100         favoriteType,
101         burstType,
102         burstType,
103         burstType};
104     return this->GetCount(this->SQL_PHOTOS_ALL_TOTAL_COUNT, params);
105 }
106 
107 /**
108  * @brief Get the row count of media_library storage in SD card.
109  * @param mediaType - 0 all, 1 picture, 3 video
110  */
QueryAllRestoreCount(SearchCondition searchCondition)111 int32_t PhotosCountStatistic::QueryAllRestoreCount(SearchCondition searchCondition)
112 {
113     CHECK_AND_RETURN_RET_LOG(this->mediaLibraryRdb_ != nullptr, 0, "Media_Restore: mediaLibraryRdb_ is null.");
114     int32_t mediaType = searchCondition.GetMediaType();
115     int32_t hiddenType = searchCondition.GetHiddenType();
116     int32_t trashedType = searchCondition.GetTrashedType();
117     int32_t cloudType = searchCondition.GetCloudType();
118     int32_t favoriteType = searchCondition.GetFavoriteType();
119     int32_t burstType = searchCondition.GetBurstType();
120     std::vector<NativeRdb::ValueObject> params = {mediaType,
121         mediaType,
122         hiddenType,
123         hiddenType,
124         hiddenType,
125         trashedType,
126         trashedType,
127         trashedType,
128         cloudType,
129         cloudType,
130         cloudType,
131         favoriteType,
132         favoriteType,
133         favoriteType,
134         burstType,
135         burstType,
136         burstType};
137     return this->GetCount(this->SQL_PHOTOS_ALL_RESTORE_COUNT, params);
138 }
139 
140 /**
141  * @brief Get the row count of media_library storage in SD card.
142  * @param mediaType - 0 all, 1 picture, 3 video
143  */
QueryPicturesTotalCount(SearchCondition searchCondition)144 int32_t PhotosCountStatistic::QueryPicturesTotalCount(SearchCondition searchCondition)
145 {
146     CHECK_AND_RETURN_RET_LOG(this->mediaLibraryRdb_ != nullptr, 0, "Media_Restore: mediaLibraryRdb_ is null.");
147     int32_t mediaType = searchCondition.GetMediaType();
148     int32_t hiddenType = searchCondition.GetHiddenType();
149     int32_t trashedType = searchCondition.GetTrashedType();
150     int32_t cloudType = searchCondition.GetCloudType();
151     int32_t favoriteType = searchCondition.GetFavoriteType();
152     int32_t burstType = searchCondition.GetBurstType();
153     std::vector<NativeRdb::ValueObject> params = {mediaType,
154         mediaType,
155         hiddenType,
156         hiddenType,
157         hiddenType,
158         trashedType,
159         trashedType,
160         trashedType,
161         cloudType,
162         cloudType,
163         cloudType,
164         favoriteType,
165         favoriteType,
166         favoriteType,
167         burstType,
168         burstType,
169         burstType};
170     return this->GetCount(this->SQL_PHOTOS_PICTURES_TOTAL_COUNT, params);
171 }
172 
173 /**
174  * @brief Get the row count of media_library.
175  * @param searchType - 0 all, 1 cloud
176  * @param mediaType - 0 all, 1 picture, 2 video
177  */
QueryAlbumCountByName(const std::string & albumName,SearchCondition searchCondition)178 std::vector<AlbumStatisticInfo> PhotosCountStatistic::QueryAlbumCountByName(
179     const std::string &albumName, SearchCondition searchCondition)
180 {
181     CHECK_AND_RETURN_RET_LOG(this->mediaLibraryRdb_ != nullptr, {}, "Media_Restore: mediaLibraryRdb_ is null.");
182     int32_t mediaType = searchCondition.GetMediaType();
183     int32_t hiddenType = searchCondition.GetHiddenType();
184     int32_t trashedType = searchCondition.GetTrashedType();
185     int32_t cloudType = searchCondition.GetCloudType();
186     int32_t favoriteType = searchCondition.GetFavoriteType();
187     int32_t burstType = searchCondition.GetBurstType();
188     std::vector<NativeRdb::ValueObject> params = {albumName,
189         mediaType,
190         mediaType,
191         hiddenType,
192         hiddenType,
193         hiddenType,
194         trashedType,
195         trashedType,
196         trashedType,
197         cloudType,
198         cloudType,
199         cloudType,
200         favoriteType,
201         favoriteType,
202         favoriteType,
203         burstType,
204         burstType,
205         burstType};
206     auto resultSet = this->mediaLibraryRdb_->QuerySql(this->SQL_PHOTOS_COUNT_BY_ALBUM_NAME, params);
207     CHECK_AND_RETURN_RET(resultSet != nullptr, {});
208     std::vector<AlbumStatisticInfo> infoList;
209     while (resultSet->GoToNextRow() == NativeRdb::E_OK) {
210         AlbumStatisticInfo info;
211         info.albumName = GetStringVal("albumName", resultSet);
212         info.count = GetInt32Val("count", resultSet);
213         info.lPath = GetStringVal("lpath", resultSet);
214         infoList.emplace_back(info);
215     }
216     resultSet->Close();
217     return infoList;
218 }
219 
220 /**
221  * @brief Get the row count of media_library.
222  * @param mediaType - 0 all, 2 cloud
223  */
QueryLiveCount(int32_t searchType)224 int32_t PhotosCountStatistic::QueryLiveCount(int32_t searchType)
225 {
226     std::vector<NativeRdb::ValueObject> params = {searchType};
227     CHECK_AND_RETURN_RET_LOG(this->mediaLibraryRdb_ != nullptr, 0, "Media_Restore: mediaLibraryRdb_ is null.");
228     return this->GetCount(this->SQL_PHOTOS_LIVE_COUNT, params);
229 }
230 
GetAllStatInfo()231 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllStatInfo()
232 {
233     AlbumMediaStatisticInfo info;
234     info.sceneCode = this->sceneCode_;
235     info.taskId = this->taskId_;
236     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
237     // build the statistic info.
238     info.totalCount = this->QueryTotalCount(SearchCondition());
239     info.imageCount = this->QueryTotalCount(SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
240     info.videoCount = this->QueryTotalCount(SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
241     info.hiddenCount = this->QueryTotalCount(SearchCondition().SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
242     info.trashedCount = this->QueryTotalCount(SearchCondition().SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
243     info.cloudCount = this->QueryTotalCount(SearchCondition().SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
244     info.favoriteCount = this->QueryTotalCount(SearchCondition().SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
245     info.burstTotalCount = this->QueryTotalCount(SearchCondition().SetBurstType(SINGLE_BURST_TYPE_ALL));
246     info.burstCoverCount = this->QueryTotalCount(SearchCondition().SetBurstType(SINGLE_BURST_TYPE_COVER));
247     // build the album name.
248     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
249     int64_t costTime = endTime - startTime;
250     std::string albumName = "ALL";
251     std::string lPath = "";
252     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
253     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
254     info.albumName = AlbumNameInfo()
255                          .SetAlbumName(albumName)
256                          .SetLPath(lPath)
257                          .SetCostTime(costTime)
258                          .SetPeriod(period)
259                          .SetDbType(dbType)
260                          .ToString();
261     return info;
262 }
263 
GetAllImageStatInfo()264 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllImageStatInfo()
265 {
266     AlbumMediaStatisticInfo info;
267     info.sceneCode = this->sceneCode_;
268     info.taskId = this->taskId_;
269     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
270     // build the statistic info.
271     SearchCondition defaultCondition = SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_IMAGE);
272     info.totalCount = this->QueryTotalCount(SearchCondition(defaultCondition));
273     info.imageCount = this->QueryTotalCount(SearchCondition(defaultCondition));
274     info.videoCount = 0;
275     info.hiddenCount =
276         this->QueryTotalCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
277     info.trashedCount =
278         this->QueryTotalCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
279     info.cloudCount = this->QueryTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
280     info.favoriteCount =
281         this->QueryTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
282     info.burstTotalCount = this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
283     info.burstCoverCount =
284         this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
285     // build the album name.
286     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
287     int64_t costTime = endTime - startTime;
288     std::string albumName = "ALL_IMAGE";
289     std::string lPath = "";
290     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
291     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
292     info.albumName = AlbumNameInfo()
293                          .SetAlbumName(albumName)
294                          .SetLPath(lPath)
295                          .SetCostTime(costTime)
296                          .SetPeriod(period)
297                          .SetDbType(dbType)
298                          .ToString();
299     return info;
300 }
301 
GetAllVideoStatInfo()302 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllVideoStatInfo()
303 {
304     AlbumMediaStatisticInfo info;
305     info.sceneCode = this->sceneCode_;
306     info.taskId = this->taskId_;
307     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
308     // build the statistic info.
309     SearchCondition defaultCondition = SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_VIDEO);
310     info.totalCount = this->QueryTotalCount(SearchCondition(defaultCondition));
311     info.imageCount = 0;
312     info.videoCount = this->QueryTotalCount(SearchCondition(defaultCondition));
313     info.hiddenCount =
314         this->QueryTotalCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
315     info.trashedCount =
316         this->QueryTotalCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
317     info.cloudCount = this->QueryTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
318     info.favoriteCount =
319         this->QueryTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
320     info.burstTotalCount = 0;
321     info.burstCoverCount = 0;
322     // build the album name.
323     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
324     int64_t costTime = endTime - startTime;
325     std::string albumName = "ALL_VIDEO";
326     std::string lPath = "";
327     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
328     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
329     info.albumName = AlbumNameInfo()
330                          .SetAlbumName(albumName)
331                          .SetLPath(lPath)
332                          .SetCostTime(costTime)
333                          .SetPeriod(period)
334                          .SetDbType(dbType)
335                          .ToString();
336     return info;
337 }
338 
GetAllRestoreStatInfo()339 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllRestoreStatInfo()
340 {
341     AlbumMediaStatisticInfo info;
342     info.sceneCode = this->sceneCode_;
343     info.taskId = this->taskId_;
344     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
345     // build the statistic info.
346     info.totalCount = this->QueryAllRestoreCount(SearchCondition());
347     info.imageCount = this->QueryAllRestoreCount(SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
348     info.videoCount = this->QueryAllRestoreCount(SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
349     info.hiddenCount = this->QueryAllRestoreCount(SearchCondition().SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
350     info.trashedCount = this->QueryAllRestoreCount(SearchCondition().SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
351     info.cloudCount = 0;
352     info.favoriteCount = this->QueryAllRestoreCount(SearchCondition().SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
353     info.burstTotalCount = this->QueryAllRestoreCount(SearchCondition().SetBurstType(SINGLE_BURST_TYPE_ALL));
354     info.burstCoverCount = this->QueryAllRestoreCount(SearchCondition().SetBurstType(SINGLE_BURST_TYPE_COVER));
355     // build the album name.
356     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
357     int64_t costTime = endTime - startTime;
358     std::string albumName = "ALL_RESTORE";
359     std::string lPath = "";
360     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
361     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
362     info.albumName = AlbumNameInfo()
363                          .SetAlbumName(albumName)
364                          .SetLPath(lPath)
365                          .SetCostTime(costTime)
366                          .SetPeriod(period)
367                          .SetDbType(dbType)
368                          .ToString();
369     return info;
370 }
371 
GetAllRestoreImageStatInfo()372 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllRestoreImageStatInfo()
373 {
374     AlbumMediaStatisticInfo info;
375     info.sceneCode = this->sceneCode_;
376     info.taskId = this->taskId_;
377     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
378     // build the statistic info.
379     SearchCondition defaultCondition = SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_IMAGE);
380     info.totalCount = this->QueryAllRestoreCount(SearchCondition(defaultCondition));
381     info.imageCount = this->QueryAllRestoreCount(SearchCondition(defaultCondition));
382     info.videoCount = 0;
383     info.hiddenCount =
384         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
385     info.trashedCount =
386         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
387     info.cloudCount = 0;
388     info.favoriteCount =
389         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
390     info.burstTotalCount =
391         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
392     info.burstCoverCount =
393         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
394     // build the album name.
395     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
396     int64_t costTime = endTime - startTime;
397     std::string albumName = "ALL_RESTORE_IMAGE";
398     std::string lPath = "";
399     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
400     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
401     info.albumName = AlbumNameInfo()
402                          .SetAlbumName(albumName)
403                          .SetLPath(lPath)
404                          .SetCostTime(costTime)
405                          .SetPeriod(period)
406                          .SetDbType(dbType)
407                          .ToString();
408     return info;
409 }
410 
GetAllRestoreVideoStatInfo()411 AlbumMediaStatisticInfo PhotosCountStatistic::GetAllRestoreVideoStatInfo()
412 {
413     AlbumMediaStatisticInfo info;
414     info.sceneCode = this->sceneCode_;
415     info.taskId = this->taskId_;
416     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
417     // build the statistic info.
418     SearchCondition defaultCondition = SearchCondition().SetMediaType(SINGLE_MEDIA_TYPE_VIDEO);
419     info.totalCount = this->QueryAllRestoreCount(SearchCondition(defaultCondition));
420     info.imageCount = 0;
421     info.videoCount = this->QueryAllRestoreCount(SearchCondition(defaultCondition));
422     info.hiddenCount =
423         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
424     info.trashedCount =
425         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
426     info.cloudCount = 0;
427     info.favoriteCount =
428         this->QueryAllRestoreCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
429     info.burstTotalCount = 0;
430     info.burstCoverCount = 0;
431     // build the album name.
432     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
433     int64_t costTime = endTime - startTime;
434     std::string albumName = "ALL_RESTORE_VIDEO";
435     std::string lPath = "";
436     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
437     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
438     info.albumName = AlbumNameInfo()
439                          .SetAlbumName(albumName)
440                          .SetLPath(lPath)
441                          .SetCostTime(costTime)
442                          .SetPeriod(period)
443                          .SetDbType(dbType)
444                          .ToString();
445     return info;
446 }
447 
GetImageAlbumInfo()448 AlbumMediaStatisticInfo PhotosCountStatistic::GetImageAlbumInfo()
449 {
450     AlbumMediaStatisticInfo info;
451     info.sceneCode = this->sceneCode_;
452     info.taskId = this->taskId_;
453     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
454     // build the statistic info.
455     SearchCondition defaultCondition = SearchCondition()
456                                            .SetMediaType(SINGLE_MEDIA_TYPE_IMAGE)
457                                            .SetHiddenType(SINGLE_HIDDEN_TYPE_NOT_HIDDEN)
458                                            .SetTrashedType(SINGLE_TRASHED_TYPE_NOT_TRASHED);
459     info.totalCount = this->QueryPicturesTotalCount(defaultCondition);
460     info.imageCount =
461         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
462     info.videoCount = 0;
463     info.hiddenCount = 0;
464     info.trashedCount = 0;
465     info.cloudCount =
466         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
467     info.favoriteCount =
468         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
469     info.burstTotalCount =
470         this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
471     info.burstCoverCount =
472         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
473     // build the album name.
474     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
475     int64_t costTime = endTime - startTime;
476     std::string albumName = "图片";
477     std::string lPath = "";
478     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
479     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
480     info.albumName = AlbumNameInfo()
481                          .SetAlbumName(albumName)
482                          .SetLPath(lPath)
483                          .SetCostTime(costTime)
484                          .SetPeriod(period)
485                          .SetDbType(dbType)
486                          .ToString();
487     return info;
488 }
489 
GetVideoAlbumInfo()490 AlbumMediaStatisticInfo PhotosCountStatistic::GetVideoAlbumInfo()
491 {
492     AlbumMediaStatisticInfo info;
493     info.sceneCode = this->sceneCode_;
494     info.taskId = this->taskId_;
495     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
496     // build the statistic info.
497     SearchCondition defaultCondition = SearchCondition()
498                                            .SetMediaType(SINGLE_MEDIA_TYPE_VIDEO)
499                                            .SetHiddenType(SINGLE_HIDDEN_TYPE_NOT_HIDDEN)
500                                            .SetTrashedType(SINGLE_TRASHED_TYPE_NOT_TRASHED);
501     info.totalCount = this->QueryPicturesTotalCount(SearchCondition(defaultCondition));
502     info.imageCount = 0;
503     info.videoCount =
504         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
505     info.hiddenCount = 0;
506     info.trashedCount = 0;
507     info.cloudCount =
508         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
509     info.favoriteCount =
510         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
511     info.burstTotalCount = 0;
512     info.burstCoverCount = 0;
513     // build the album name.
514     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
515     int64_t costTime = endTime - startTime;
516     std::string albumName = "视频";
517     std::string lPath = "";
518     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
519     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
520     info.albumName = AlbumNameInfo()
521                          .SetAlbumName(albumName)
522                          .SetLPath(lPath)
523                          .SetCostTime(costTime)
524                          .SetPeriod(period)
525                          .SetDbType(dbType)
526                          .ToString();
527     return info;
528 }
529 
GetAlbumInfoByName(const std::string & albumName)530 std::vector<AlbumMediaStatisticInfo> PhotosCountStatistic::GetAlbumInfoByName(const std::string &albumName)
531 {
532     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
533     // build the statistic info.
534     SearchCondition defaultCondition =
535         SearchCondition().SetHiddenType(SINGLE_HIDDEN_TYPE_NOT_HIDDEN).SetTrashedType(SINGLE_TRASHED_TYPE_NOT_TRASHED);
536     std::vector<AlbumStatisticInfo> totalCountInfoList =
537         this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition));
538     std::vector<AlbumStatisticInfo> imageCountInfoList =
539         this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
540     std::vector<AlbumStatisticInfo> videoCountInfoList =
541         this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
542     std::vector<AlbumStatisticInfo> cloudCountInfoList =
543         this->QueryAlbumCountByName(albumName, SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
544     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
545     int64_t costTime = endTime - startTime;
546     // Parse the statistic info.
547     std::unordered_map<std::string, AlbumMediaStatisticInfo> albumInfoMap;
548     StatisticProcessor()
549         .ParseTotalCount(albumInfoMap, totalCountInfoList)
550         .ParseImageCount(albumInfoMap, imageCountInfoList)
551         .ParseVideoCount(albumInfoMap, videoCountInfoList)
552         .ParseCloudCount(albumInfoMap, cloudCountInfoList);
553     std::vector<AlbumMediaStatisticInfo> albumInfoList;
554     for (const auto &iter : albumInfoMap) {
555         AlbumMediaStatisticInfo info = iter.second;
556         info.sceneCode = this->sceneCode_;
557         info.taskId = this->taskId_;
558         info.albumName = AlbumNameInfo()
559                              .SetAlbumName(albumName)
560                              .SetLPath(info.lPath)
561                              .SetCostTime(costTime)
562                              .SetPeriod(this->period_)  // 0 - BEFORE, 1 - AFTER
563                              .SetDbType(1)  // 0 - GALLERY, 1 - MEDIA
564                              .ToString();
565         albumInfoList.emplace_back(info);
566     }
567     return albumInfoList;
568 }
569 
GetFavoriteAlbumStatInfo()570 AlbumMediaStatisticInfo PhotosCountStatistic::GetFavoriteAlbumStatInfo()
571 {
572     AlbumMediaStatisticInfo info;
573     info.sceneCode = this->sceneCode_;
574     info.taskId = this->taskId_;
575     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
576     // build the statistic info.
577     SearchCondition defaultCondition = SearchCondition().SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE);
578     info.totalCount = this->QueryPicturesTotalCount(SearchCondition(defaultCondition));
579     info.imageCount =
580         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
581     info.videoCount =
582         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
583     info.hiddenCount = 0;
584     info.trashedCount = 0;
585     info.cloudCount =
586         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
587     info.favoriteCount =
588         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
589     info.burstTotalCount =
590         this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
591     info.burstCoverCount =
592         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
593     // build the album name.
594     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
595     int64_t costTime = endTime - startTime;
596     std::string albumName = "收藏";
597     std::string lPath = "";
598     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
599     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
600     info.albumName = AlbumNameInfo()
601                          .SetAlbumName(albumName)
602                          .SetLPath(lPath)
603                          .SetCostTime(costTime)
604                          .SetPeriod(period)
605                          .SetDbType(dbType)
606                          .ToString();
607     return info;
608 }
609 
GetTrashedAlbumStatInfo()610 AlbumMediaStatisticInfo PhotosCountStatistic::GetTrashedAlbumStatInfo()
611 {
612     AlbumMediaStatisticInfo info;
613     info.sceneCode = this->sceneCode_;
614     info.taskId = this->taskId_;
615     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
616     // build the statistic info.
617     SearchCondition defaultCondition = SearchCondition().SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED);
618     info.totalCount = this->QueryPicturesTotalCount(SearchCondition(defaultCondition));
619     info.imageCount =
620         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
621     info.videoCount =
622         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
623     info.hiddenCount =
624         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
625     info.trashedCount =
626         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
627     info.cloudCount =
628         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
629     info.favoriteCount =
630         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
631     info.burstTotalCount =
632         this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
633     info.burstCoverCount =
634         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
635     // build the album name.
636     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
637     int64_t costTime = endTime - startTime;
638     std::string albumName = "回收站";
639     std::string lPath = "";
640     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
641     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
642     info.albumName = AlbumNameInfo()
643                          .SetAlbumName(albumName)
644                          .SetLPath(lPath)
645                          .SetCostTime(costTime)
646                          .SetPeriod(period)
647                          .SetDbType(dbType)
648                          .ToString();
649     return info;
650 }
651 
GetHiddenAlbumStatInfo()652 AlbumMediaStatisticInfo PhotosCountStatistic::GetHiddenAlbumStatInfo()
653 {
654     AlbumMediaStatisticInfo info;
655     info.sceneCode = this->sceneCode_;
656     info.taskId = this->taskId_;
657     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
658     // build the statistic info.
659     SearchCondition defaultCondition = SearchCondition().SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN);
660     info.totalCount = this->QueryPicturesTotalCount(SearchCondition(defaultCondition));
661     info.imageCount =
662         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_IMAGE));
663     info.videoCount =
664         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetMediaType(SINGLE_MEDIA_TYPE_VIDEO));
665     info.hiddenCount =
666         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetHiddenType(SINGLE_HIDDEN_TYPE_HIDDEN));
667     info.trashedCount =
668         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetTrashedType(SINGLE_TRASHED_TYPE_TRASHED));
669     info.cloudCount =
670         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetCloudType(SINGLE_CLOUD_TYPE_CLOUD));
671     info.favoriteCount =
672         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetFavoriteType(SINGLE_FAVORITE_TYPE_FAVORITE));
673     info.burstTotalCount =
674         this->QueryTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_ALL));
675     info.burstCoverCount =
676         this->QueryPicturesTotalCount(SearchCondition(defaultCondition).SetBurstType(SINGLE_BURST_TYPE_COVER));
677     // build the album name.
678     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
679     int64_t costTime = endTime - startTime;
680     std::string albumName = "隐藏";
681     std::string lPath = "";
682     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
683     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
684     info.albumName = AlbumNameInfo()
685                          .SetAlbumName(albumName)
686                          .SetLPath(lPath)
687                          .SetCostTime(costTime)
688                          .SetPeriod(period)
689                          .SetDbType(dbType)
690                          .ToString();
691     return info;
692 }
693 
GetGalleryAlbumCountInfo()694 AlbumMediaStatisticInfo PhotosCountStatistic::GetGalleryAlbumCountInfo()
695 {
696     AlbumMediaStatisticInfo info;
697     info.sceneCode = this->sceneCode_;
698     info.taskId = this->taskId_;
699     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
700     // build the statistic info.
701     info.totalCount = this->GetCount(SQL_PHOTO_ALBUM_COUNT);
702     // build the album name.
703     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
704     int64_t costTime = endTime - startTime;
705     std::string albumName = "相册数量";
706     std::string lPath = "";
707     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
708     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
709     info.albumName = AlbumNameInfo()
710                          .SetAlbumName(albumName)
711                          .SetLPath(lPath)
712                          .SetCostTime(costTime)
713                          .SetPeriod(period)
714                          .SetDbType(dbType)
715                          .ToString();
716     return info;
717 }
718 
GetGalleryDeletedAlbumCountInfo()719 AlbumMediaStatisticInfo PhotosCountStatistic::GetGalleryDeletedAlbumCountInfo()
720 {
721     AlbumMediaStatisticInfo info;
722     info.sceneCode = this->sceneCode_;
723     info.taskId = this->taskId_;
724     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
725     // build the statistic info.
726     std::vector<NativeRdb::ValueObject> params = {static_cast<int32_t>(DirtyType::TYPE_DELETED)};
727     info.totalCount = this->GetCount(SQL_PHOTO_DELETED_ALBUM_COUNT, params);
728     // build the album name.
729     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
730     int64_t costTime = endTime - startTime;
731     std::string albumName = "DELETED_ALBUM";
732     std::string lPath = "";
733     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
734     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
735     info.albumName = AlbumNameInfo()
736                          .SetAlbumName(albumName)
737                          .SetLPath(lPath)
738                          .SetCostTime(costTime)
739                          .SetPeriod(period)
740                          .SetDbType(dbType)
741                          .ToString();
742     return info;
743 }
744 
GetLiveStatInfo()745 AlbumMediaStatisticInfo PhotosCountStatistic::GetLiveStatInfo()
746 {
747     AlbumMediaStatisticInfo info;
748     info.sceneCode = this->sceneCode_;
749     info.taskId = this->taskId_;
750     int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
751     // build the statistic info.
752     info.totalCount = this->QueryLiveCount(SINGLE_SEARCH_TYPE_ALL);
753     info.cloudCount = this->QueryLiveCount(SINGLE_SEARCH_TYPE_CLOUD);
754     // build the album name.
755     int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
756     int64_t costTime = endTime - startTime;
757     std::string albumName = "动态照片";
758     std::string lPath = "";
759     int32_t period = this->period_;  // 0 - BEFORE, 1 - AFTER
760     int32_t dbType = 1;              // 0 - GALLERY, 1 - MEDIA
761     info.albumName = AlbumNameInfo()
762                          .SetAlbumName(albumName)
763                          .SetLPath(lPath)
764                          .SetCostTime(costTime)
765                          .SetPeriod(period)
766                          .SetDbType(dbType)
767                          .ToString();
768     return info;
769 }
770 }  // namespace OHOS::Media