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 "external_files_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
22 namespace OHOS::Media {
Load()23 std::vector<AlbumMediaStatisticInfo> ExternalFilesCountStatistic::Load()
24 {
25 if (this->externalRdb_ == nullptr) {
26 MEDIA_ERR_LOG("externalRdb_ is nullptr, Maybe init failed.");
27 return {};
28 }
29 return {this->GetMediaStatInfo(), this->GetAudioStatInfo()};
30 }
31
GetMediaStatInfo()32 AlbumMediaStatisticInfo ExternalFilesCountStatistic::GetMediaStatInfo()
33 {
34 int32_t externalImageCount = this->QueryExternalImageCount();
35 int32_t externalVideoCount = this->QueryExternalVideoCount();
36 AlbumMediaStatisticInfo info;
37 info.sceneCode = this->sceneCode_;
38 info.taskId = this->taskId_;
39 info.albumName = "External_Media";
40 info.imageCount = externalImageCount;
41 info.videoCount = externalVideoCount;
42 return info;
43 }
44
GetAudioStatInfo()45 AlbumMediaStatisticInfo ExternalFilesCountStatistic::GetAudioStatInfo()
46 {
47 int32_t externalAudioCount = this->QueryExternalAudioCount();
48 AlbumMediaStatisticInfo info;
49 info.sceneCode = this->sceneCode_;
50 info.taskId = this->taskId_;
51 info.albumName = "External_Audio";
52 info.totalCount = externalAudioCount;
53 return info;
54 }
55
QueryExternalAudioCount()56 int32_t ExternalFilesCountStatistic::QueryExternalAudioCount()
57 {
58 static string QUERY_EXTERNAL_AUDIO_COUNT = "SELECT count(1) as count FROM files WHERE media_type = 2 AND _size > 0 \
59 AND _data LIKE '/storage/emulated/0/Music%'";
60 return BackupDatabaseUtils::QueryInt(this->externalRdb_, QUERY_EXTERNAL_AUDIO_COUNT, CUSTOM_COUNT);
61 }
62
QueryExternalImageCount()63 int32_t ExternalFilesCountStatistic::QueryExternalImageCount()
64 {
65 static string QUERY_EXTERNAL_IMAGE_COUNT =
66 "SELECT count(1) AS count FROM files WHERE media_type = 1 AND _size > 0";
67 return BackupDatabaseUtils::QueryInt(this->externalRdb_, QUERY_EXTERNAL_IMAGE_COUNT, CUSTOM_COUNT);
68 }
69
QueryExternalVideoCount()70 int32_t ExternalFilesCountStatistic::QueryExternalVideoCount()
71 {
72 static string QUERY_EXTERNAL_VIDEO_COUNT =
73 "SELECT count(1) AS count FROM files WHERE media_type = 3 AND _size > 0";
74 return BackupDatabaseUtils::QueryInt(this->externalRdb_, QUERY_EXTERNAL_VIDEO_COUNT, CUSTOM_COUNT);
75 }
76 } // namespace OHOS::Media