1 /* 2 * Copyright (C) 2025-2025 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 16 #ifndef OHOS_MEDIA_PHOTO_STORAGE_OPERATION_H 17 #define OHOS_MEDIA_PHOTO_STORAGE_OPERATION_H 18 19 #include <string> 20 21 #include "medialibrary_rdbstore.h" 22 23 namespace OHOS::Media { 24 25 struct TotalThumbnailSizeResult { 26 int64_t totalThumbnailSize; 27 int32_t thumbnailCount; 28 }; 29 30 struct TotalEditdataSizeResult { 31 int64_t totalEditdataSize; 32 int32_t editdataCount; 33 }; 34 35 struct LocalPhotoSizeResult { 36 int64_t localImageSize; 37 int64_t localVideoSize; 38 }; 39 40 class PhotoStorageOperation { 41 public: 42 std::shared_ptr<NativeRdb::ResultSet> FindStorage(std::shared_ptr<MediaLibraryRdbStore> mediaRdbStorePtr); 43 std::shared_ptr<NativeRdb::ResultSet> QueryHighlightDirectorySize(std::shared_ptr<MediaLibraryRdbStore> rdbStore); 44 int64_t GetCacheSize(); 45 int64_t GetHighlightSizeFromPreferences(); 46 void GetTotalThumbnailSize(std::shared_ptr<MediaLibraryRdbStore> rdbStore, 47 TotalThumbnailSizeResult &totalThumbnailSizeResult); 48 49 void GetTotalEditdataSize(std::shared_ptr<MediaLibraryRdbStore> rdbStore, 50 TotalEditdataSizeResult &totalEditdataSizeResult); 51 void GetLocalPhotoSize(std::shared_ptr<MediaLibraryRdbStore> rdbStore, LocalPhotoSizeResult &localPhotoSizeResult, 52 int64_t totalExtSize); 53 54 private: 55 int64_t GetHighlightSize(); 56 void SaveHighlightSizeToPreferences(int64_t size); 57 58 private: 59 // media_type : 1-photo, 2-video, -1-thumbnail & cache 60 const std::string SQL_DB_STORAGE_QUERY = "\ 61 SELECT \ 62 media_type, \ 63 SUM(size) AS size \ 64 FROM Photos \ 65 WHERE \ 66 media_type IN (1, 2) AND \ 67 position != 2 \ 68 GROUP BY media_type \ 69 UNION \ 70 SELECT \ 71 -1 AS media_type, \ 72 ? AS size \ 73 FROM tab_photos_ext \ 74 ;"; 75 }; 76 } // namespace OHOS::Media 77 #endif // OHOS_MEDIA_PHOTO_STORAGE_OPERATION_H