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