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