• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-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_BACKUP_DEFINES_H
17 #define OHOS_MEDIA_BACKUP_DEFINES_H
18 
19 #include <string>
20 #include <unordered_set>
21 #include <variant>
22 #include <vector>
23 #include <optional>
24 
25 #include "photo_album_column.h"
26 #include "photo_map_column.h"
27 #include "vision_column.h"
28 
29 namespace OHOS {
30 namespace Media {
31 constexpr int32_t QUERY_COUNT = 200;
32 constexpr int32_t PRE_CLONE_PHOTO_BATCH_COUNT = 100;
33 constexpr int32_t CONNECT_SIZE = 10;
34 constexpr int32_t MILLISECONDS = 1000;
35 constexpr int32_t GALLERY_HIDDEN_ID = -4;
36 constexpr int32_t GALLERY_TRASHED_ID = 0;
37 constexpr int32_t UPGRADE_RESTORE_ID = 0;
38 constexpr int32_t DUAL_FRAME_CLONE_RESTORE_ID = 1;
39 constexpr int32_t CLONE_RESTORE_ID = 2;
40 constexpr int32_t I_PHONE_CLONE_RESTORE = 3;
41 constexpr int32_t OTHERS_PHONE_CLONE_RESTORE = 4;
42 constexpr int32_t LITE_PHONE_CLONE_RESTORE = 5;
43 constexpr int32_t DEFAULT_RESTORE_ID = -1;
44 constexpr int32_t RETRY_TIME = 5;
45 constexpr int32_t SLEEP_INTERVAL = 1;
46 constexpr int32_t GARBAGE_PHOTO_SIZE = 2048;
47 constexpr int32_t LIVE_PHOTO_TYPE = 50;
48 constexpr int32_t LIVE_PHOTO_HDR_TYPE = 1050;
49 constexpr size_t GARBLE_UNIT = 2;
50 constexpr uint32_t COVER_URI_NUM = 3;
51 constexpr int32_t EXTERNAL_DB_NOT_EXIST = -3;
52 constexpr uint32_t UNIQUE_NUMBER_NUM = 3;
53 constexpr uint32_t THUMBNAIL_NUM = 500;
54 constexpr size_t MAX_FAILED_FILES_LIMIT = 100;
55 constexpr int64_t TAR_FILE_LIMIT = 2 * 1024 * 1024;
56 constexpr int32_t MAX_THREAD_NUM = 4;
57 
58 const std::string RESTORE_FILES_CLOUD_DIR = "/storage/cloud/files/";
59 const std::string RESTORE_FILES_LOCAL_DIR = "/storage/media/local/files/";
60 const std::string RESTORE_CLOUD_DIR = "/storage/cloud/files/Photo";
61 const std::string RESTORE_AUDIO_CLOUD_DIR = "/storage/cloud/files/Audio";
62 const std::string RESTORE_LOCAL_DIR = "/storage/media/local/files/Photo";
63 const std::string RESTORE_AUDIO_LOCAL_DIR = "/storage/media/local/files/Audio";
64 const std::string RESTORE_MUSIC_LOCAL_DIR = "/storage/media/local/files/Docs/Music/";
65 const std::string UPGRADE_FILE_DIR = "/storage/media/local/files/data";
66 const std::string GARBLE_DUAL_FRAME_CLONE_DIR = "/storage/media/local/files/data/storage/emulated";
67 const std::string OTHER_CLONE_PATH = "/storage/media/local/files/.backup/restore/";
68 const std::string GARBLE = "***";
69 const std::string GALLERT_IMPORT = "/Pictures/cloud/Imports";
70 const std::string GALLERT_HIDDEN_ALBUM = "/Pictures/hiddenAlbum";
71 const std::string GALLERT_ROOT_PATH = "/storage/emulated/";
72 const std::string RESTORE_FAILED_FILES_PATH = "/storage/media/local/files/Docs/Documents/restore_failed_files";
73 const std::string PHOTO_FILTER_SELECTED_SIZE = "filter_selected_size";
74 const std::string RESTORE_SANDBOX_DIR = "/data/storage/el2/base/.backup/restore";
75 
76 // DB field for update scene
77 const std::string GALLERY_ID = "_id";
78 const std::string GALLERY_LOCAL_MEDIA_ID = "local_media_id";
79 const std::string GALLERY_FILE_DATA = "_data";
80 const std::string GALLERY_TITLE = "title";
81 const std::string GALLERY_DISPLAY_NAME = "_display_name";
82 const std::string GALLERY_DESCRIPTION = "description";
83 const std::string GALLERY_IS_FAVORITE = "is_hw_favorite";
84 const std::string GALLERY_IS_BURST = "is_hw_burst";
85 const std::string GALLERY_RECYCLED_TIME = "recycledTime";
86 const std::string GALLERY_FILE_SIZE = "_size";
87 const std::string GALLERY_DURATION = "duration";
88 const std::string GALLERY_MEDIA_TYPE = "media_type";
89 const std::string GALLERY_SHOW_DATE_TOKEN = "showDateToken";
90 const std::string GALLERY_HEIGHT = "height";
91 const std::string GALLERY_WIDTH = "width";
92 const std::string GALLERY_ORIENTATION = "orientation";
93 const std::string GALLERY_MEDIA_BUCKET_ID = "relative_bucket_id";
94 const std::string GALLERY_MEDIA_SOURCE_PATH = "sourcePath";
95 const std::string GALLERY_RECYCLE_FLAG = "recycleFlag";
96 const std::string GALLERY_HASH = "hash";
97 const std::string GALLERY_SPECIAL_FILE_TYPE = "special_file_type";
98 const std::string GALLERY_FIRST_UPDATE_TIME = "first_update_time";
99 const std::string GALLERY_DATE_TAKEN = "datetaken";
100 const std::string GALLERY_DETAIL_TIME = "detail_time";
101 
102 // external column
103 const std::string EXTERNAL_IS_FAVORITE = "is_favorite";
104 const std::string EXTERNAL_DATE_MODIFIED = "date_modified";
105 const std::string EXTERNAL_DATE_ADDED = "date_added";
106 const std::string EXTERNAL_FILE_DATA = "_data";
107 const std::string EXTERNAL_TITLE = "title";
108 const std::string EXTERNAL_DISPLAY_NAME = "_display_name";
109 const std::string EXTERNAL_FILE_SIZE = "_size";
110 const std::string EXTERNAL_DURATION = "duration";
111 const std::string EXTERNAL_MEDIA_TYPE = "media_type";
112 const std::string EXTERNAL_DATE_TAKEN = "datetaken";
113 
114 // custom column
115 const std::string CUSTOM_COUNT = "count";
116 const std::string UNIQUE_NUMBER = "unique_number";
117 const std::string CUSTOM_MAX_ID = "max_id";
118 const std::string PRAGMA_TABLE_NAME = "name";
119 const std::string PRAGMA_TABLE_TYPE = "type";
120 
121 // audio column
122 const std::string AUDIO_DATA = "_data";
123 const std::string AUDIO_DATE_MODIFIED = "date_modified";
124 const std::string AUDIO_DATE_TAKEN = "datetaken";
125 
126 // statistics
127 const int32_t STAT_DEFAULT_ERROR_CODE_SUCCESS = 0;
128 const int32_t STAT_DEFAULT_ERROR_CODE_FAILED = 13500099;
129 const std::string STAT_KEY_RESULT_INFO = "resultInfo";
130 const std::string STAT_KEY_TYPE = "type";
131 const std::string STAT_KEY_ERROR_CODE = "errorCode";
132 const std::string STAT_KEY_ERROR_INFO = "errorInfo";
133 const std::string STAT_KEY_INFOS = "infos";
134 const std::string STAT_KEY_BACKUP_INFO = "backupInfo";
135 const std::string STAT_KEY_SUCCESS_COUNT = "successCount";
136 const std::string STAT_KEY_DUPLICATE_COUNT = "duplicateCount";
137 const std::string STAT_KEY_FAILED_COUNT = "failedCount";
138 const std::string STAT_KEY_DETAILS = "details";
139 const std::string STAT_KEY_NUMBER = "number";
140 const std::string STAT_KEY_PROGRESS_INFO = "progressInfo";
141 const std::string STAT_KEY_NAME = "name";
142 const std::string STAT_KEY_PROCESSED = "processed";
143 const std::string STAT_KEY_TOTAL = "total";
144 const std::string STAT_KEY_IS_PERCENTAGE = "isPercentage";
145 const std::string STAT_VALUE_ERROR_INFO = "ErrorInfo";
146 const std::string STAT_VALUE_COUNT_INFO = "CountInfo";
147 const std::string STAT_TYPE_PHOTO = "photo";
148 const std::string STAT_TYPE_VIDEO = "video";
149 const std::string STAT_TYPE_AUDIO = "audio";
150 const std::string STAT_TYPE_TOTAL_SIZE = "totalSize";
151 const std::string STAT_TYPE_PHOTO_VIDEO = "photo&video";
152 const std::string STAT_TYPE_UPDATE = "update";
153 const std::string STAT_TYPE_OTHER = "other";
154 const std::string STAT_TYPE_ONGOING = "ongoing";
155 const std::vector<std::string> STAT_TYPES = { STAT_TYPE_PHOTO, STAT_TYPE_VIDEO, STAT_TYPE_AUDIO };
156 const std::vector<std::string> STAT_PROGRESS_TYPES = { STAT_TYPE_PHOTO_VIDEO, STAT_TYPE_AUDIO, STAT_TYPE_UPDATE,
157     STAT_TYPE_OTHER, STAT_TYPE_ONGOING };
158 
159 const std::string GALLERY_DB_NAME = "gallery.db";
160 const std::string EXTERNAL_DB_NAME = "external.db";
161 const std::string AUDIO_DB_NAME = "audio_MediaInfo.db";
162 const std::string PHOTO_SD_DB_NAME = "photo_sd_Cache.db";
163 const std::string VIDEO_SD_DB_NAME = "video_sd_Cache.db";
164 
165 const std::string GALLERY_ALBUM = "gallery_album";
166 const std::string GALLERY_ALBUM_NAME = "albumName";
167 const std::string GALLERY_ALBUM_BUCKETID = "relativeBucketId";
168 const std::string GALLERY_ALBUM_IPATH = "lPath";
169 const std::string GALLERY_NICK_NAME = "nick_name";
170 
171 /**
172  * If the value of thumbnail_ready is greater than or equal to 3, the THM is generated successfully.
173  * If the value of thumbnail_ready is greater than 0, the value of thumbnail_visible is 1, indicating
174  * that the THM has been generated(not necessarily successfully generated).
175  * If lcd_visit_time is 2, the LCD is generated successfully.
176  * If lcd_visit_time is 0, the LCD is not generated or fails to be generated.
177 */
178 const int RESTORE_THUMBNAIL_READY_SUCCESS = 3;
179 const int RESTORE_THUMBNAIL_READY_NO_THUMBNAIL = 0;
180 const int RESTORE_THUMBNAIL_VISIBLE_FALSE = 0;
181 const int RESTORE_THUMBNAIL_VISIBLE_TRUE = 1;
182 const int RESTORE_LCD_VISIT_TIME_SUCCESS = 2;
183 const int RESTORE_LCD_VISIT_TIME_NO_LCD = 0;
184 
185 const std::string MEDIA_KVSTORE_MONTH_STOREID = "medialibrary_month_astc_data";
186 const std::string MEDIA_KVSTORE_YEAR_STOREID = "medialibrary_year_astc_data";
187 const std::string CLONE_KVSTORE_MONTH_STOREID = "medialibrary_month_astc_data_clone";
188 const std::string CLONE_KVSTORE_YEAR_STOREID = "medialibrary_year_astc_data_clone";
189 const std::string MEDIA_KVDB_DIR = "/data/storage/el2/database";
190 const std::string CLONE_KVDB_BACKUP_DIR = "/storage/media/local/files/.backup/backup/media_temp_kvdb";
191 
192 const std::string FILE_SEPARATOR = "/";
193 
194 constexpr int32_t INDEX_TYPE = 0;
195 constexpr int32_t INDEX_CACHE_DIR = 1;
196 constexpr int32_t INDEX_NICK_DIR = 2;
197 constexpr int32_t INDEX_NICK_NAME = 3;
198 
199 constexpr int32_t NICK = 0;
200 constexpr int32_t CACHE = 1;
201 
202 constexpr int32_t DEFAULT_AREA_VERSION = -1;
203 
204 enum SourceType {
205     GALLERY = 0,
206     EXTERNAL_CAMERA,
207     EXTERNAL_OTHERS,
208     PHOTOS,
209     AUDIOS,
210 };
211 
212 enum class PrefixType {
213     CLOUD = 0,
214     LOCAL,
215     CLOUD_EDIT_DATA,
216     LOCAL_EDIT_DATA,
217 };
218 
219 enum DUAL_MEDIA_TYPE {
220     IMAGE_TYPE = 1,
221     AUDIO_TYPE,
222     VIDEO_TYPE,
223 };
224 
225 enum RestoreError {
226     SUCCESS = 0,
227     INIT_FAILED,
228     FILE_INVALID,
229     PATH_INVALID,
230     GET_PATH_FAILED,
231     INSERT_FAILED,
232     MOVE_FAILED,
233     MEDIA_TYPE_INVALID,
234     DUPLICATE_DATA,
235     SIZE_INVALID,
236     MOVING_PHOTO_CONVERT_FAILED,
237     CREATE_PATH_FAILED,
238     PREPARE_PATH_FAILED,
239     GALLERY_DATABASE_CORRUPTION,
240     UPDATE_PHOTOS_FAILED,
241 };
242 
243 enum class PhotoRelatedType {
244     PHOTO_MAP = 0,
245     PORTRAIT,
246 };
247 
248 enum ProcessStatus {
249     STOP = 0,
250     START,
251 };
252 
253 const std::unordered_map<int32_t, std::string> RESTORE_ERROR_MAP = {
254     { RestoreError::INIT_FAILED, "RESTORE_INIT_FAILED" },
255     { RestoreError::FILE_INVALID, "DEVICE_FILE_INVALID" },
256     { RestoreError::PATH_INVALID, "DEVICE_PATH_INVALID" },
257     { RestoreError::GET_PATH_FAILED, "RESTORE_GET_PATH_FAILED" },
258     { RestoreError::INSERT_FAILED, "RESTORE_INSERT_FAILED" },
259     { RestoreError::MOVE_FAILED, "RESTORE_MOVE_FAILED" },
260     { RestoreError::MEDIA_TYPE_INVALID, "DEVICE_MEDIA_TYPE_INVALID" },
261     { RestoreError::DUPLICATE_DATA, "DEVICE_DUPLICATE_DATA" },
262     { RestoreError::SIZE_INVALID, "DEVICE_SIZE_INVALID" },
263     { RestoreError::MOVING_PHOTO_CONVERT_FAILED, "DEVICE_MOVING_PHOTO_CONVERT_FAILED" },
264     { RestoreError::CREATE_PATH_FAILED, "RESTORE_CREATE_PATH_FAILED" },
265     { RestoreError::PREPARE_PATH_FAILED, "RESTORE_PREPARE_PATH_FAILED" },
266     { RestoreError::GALLERY_DATABASE_CORRUPTION, "RESTORE_GALLERY_DATABASE_CORRUPTION" },
267     { RestoreError::UPDATE_PHOTOS_FAILED, "RESTORE_UPDATE_PHOTOS_FAILED"}
268 };
269 
270 const std::unordered_map<PrefixType, std::string> PREFIX_MAP = {
271     { PrefixType::CLOUD, "/storage/cloud/files" },
272     { PrefixType::LOCAL, "/storage/media/local/files" },
273     { PrefixType::CLOUD_EDIT_DATA, "/storage/cloud/files/.editData" },
274     { PrefixType::LOCAL_EDIT_DATA, "/storage/media/local/files/.editData" },
275 };
276 
277 const std::vector<std::vector<std::string>> CLONE_TABLE_LISTS_AUDIO = {
278     { AudioColumn::AUDIOS_TABLE },
279 };
280 
281 const std::vector<std::vector<std::string>> CLONE_TABLE_LISTS_PHOTO = {
282     { PhotoColumn::PHOTOS_TABLE },
283     { PhotoAlbumColumns::TABLE, PhotoMap::TABLE },
284     { ANALYSIS_ALBUM_TABLE, ANALYSIS_PHOTO_MAP_TABLE },
285 };
286 
287 const std::vector<std::vector<std::string>> CLONE_TABLE_LISTS_OLD_DEVICE = {
288     { PhotoColumn::PHOTOS_TABLE },
289     { AudioColumn::AUDIOS_TABLE },
290 };
291 
292 struct FileInfo {
293     std::string filePath;
294     std::string displayName;
295     std::string title;
296     std::string userComment;
297     std::string relativePath;
298     std::string cloudPath;
299     std::string packageName;
300     std::string bundleName;
301     std::string oldPath;
302     std::string movingPhotoVideoPath;
303     std::string extraDataPath;
304     std::string detailTime;
305     int32_t fileIdOld {-1};
306     int32_t fileIdNew {-1};
307     int64_t fileSize {0};
308     int64_t duration {0};
309     int64_t recycledTime {0};
310     int64_t dateTrashed {0};
311     int32_t hidden {0};
312     int32_t isFavorite {0};
313     int32_t fileType {0};
314     int32_t specialFileType {0};
315     int32_t subtype {0};
316     int64_t showDateToken {0};
317     int32_t height {0};
318     int32_t width {0};
319     int64_t dateAdded {0};
320     int32_t orientation {0};
321     int64_t dateModified {0};
322     int32_t mediaAlbumId {-1};  // 单相册id
323     int32_t localMediaId {-1};
324     bool isNew {true};
325     int64_t dateTaken {0};
326     int64_t firstUpdateTime {0};
327     int64_t thumbnailReady {0};
328     int32_t lcdVisitTime {0};
329     int32_t strongAssociation {0};
330     std::unordered_map<std::string, std::variant<int32_t, int64_t, double, std::string>> valMap;
331     std::unordered_map<std::string, std::unordered_set<int32_t>> tableAlbumSetMap;
332     /**
333      * @brief the field data from gallery.db # gallery_media # relative_bucket_id.
334      */
335     std::string relativeBucketId;
336     /**
337      * @brief the field data from gallery.db # gallery_media # recycleFlag.
338      */
339     int32_t recycleFlag {0};
340     /**
341      * @brief the field data from gallery.db # gallery_media # is_hw_burst. 0=normal, 1=burst cover, 2=burst members.
342      */
343     int32_t isBurst {0};
344     /**
345      * @brief the field data from gallery.db # gallery_media # hash.
346      */
347     std::string hashCode;
348     /**
349      * @brief the field data for media_library.db # Photos # burst_key. 36 length of uuid.
350      */
351     std::string burstKey;
352     /**
353      *  @brief the associate file id, used for cloud enhancement pair relationship
354      */
355     int32_t associateFileId;
356 
357     bool needMove {true};
358 
359     std::string sourcePath;
360     std::string lPath;
361     int32_t ownerAlbumId;
362     /**
363      * @brief The PhotoMap is Deprecated. Hitory Data may still be transfered from Old Device by PhotoMap.
364      *   Use the isRelatedToPhotoMap field to identify if the photo is related to PhotoMap.
365      *   0 - not related, 1 - related.
366      */
367     int32_t isRelatedToPhotoMap = 0;
368     int32_t photoQuality;
369     std::string oldAstcDateKey;
370     std::string newAstcDateKey;
371     bool isInternal {true};
372     int32_t userId {-1};
373     std::unordered_map<std::string, std::string> updateMap;
374 };
375 
376 struct AlbumInfo {
377     int32_t albumIdOld {-1};
378     int32_t albumIdNew {-1};
379     std::string albumName;
380     std::string albumBundleName;
381     PhotoAlbumType albumType;
382     PhotoAlbumSubType albumSubType;
383     std::string lPath;
384     std::unordered_map<std::string, std::variant<int32_t, int64_t, double, std::string>> valMap;
385     int64_t dateModified {0};
386 };
387 
388 struct GalleryAlbumInfo {
389     int32_t mediaAlbumId {-1};  // 单相册id
390     std::string albumRelativeBucketId ;  //双相册id
391     std::string albumName;        //相册名称
392     std::string albumNickName;   //映射表名称
393     std::string albumCNName;     //映射表名称
394     std::string albumENName;     //映射表名称
395     std::string albumListName;      //白名单相册名称
396     std::string albumBundleName;    //白名单包名
397     std::string albumMediaName;     //单相册名称
398     std::string albumlPath;     //相册IPath
399 };
400 
401 struct MapInfo {
402     int32_t albumId {-1};
403     int32_t fileId {-1};
404 };
405 
406 struct FailedFileInfo {
407     std::string albumName;
408     std::string displayName;
409     std::string errorCode;
410     FailedFileInfo() = default;
FailedFileInfoFailedFileInfo411     FailedFileInfo(int32_t sceneCode, const FileInfo &fileInfo, int32_t givenErrorCode)
412     {
413         displayName = fileInfo.displayName;
414         errorCode = std::to_string(givenErrorCode);
415         if (fileInfo.recycledTime > 0) {
416             albumName = "最近删除";
417             return;
418         }
419         if (fileInfo.hidden > 0) {
420             albumName = sceneCode == CLONE_RESTORE_ID ? "已隐藏" : "隐藏相册";
421             return;
422         }
423         albumName = fileInfo.packageName;
424     }
425 };
426 
427 struct SubCountInfo {
428     uint64_t successCount {0};
429     uint64_t duplicateCount {0};
430     std::unordered_map<std::string, FailedFileInfo> failedFiles;
SubCountInfoSubCountInfo431     SubCountInfo(int64_t successCount, int64_t duplicateCount,
432         const std::unordered_map<std::string, FailedFileInfo> &failedFiles)
433         : successCount(successCount), duplicateCount(duplicateCount), failedFiles(failedFiles) {}
434 };
435 
436 struct SubProcessInfo {
437     uint64_t processed {0};
438     uint64_t total {0};
SubProcessInfoSubProcessInfo439     SubProcessInfo(uint64_t processed, uint64_t total) : processed(processed), total(total) {}
440 };
441 
442 struct PortraitAlbumInfo {
443     int32_t userOperation {0};
444     int32_t renameOperation {0};
445     std::string tagIdOld;
446     std::string tagIdNew;
447     std::string groupTagOld;
448     std::string groupTagNew;
449     std::string tagName;
450 };
451 
452 struct FaceInfo {
453     float scaleX {0.0};
454     float scaleY {0.0};
455     float scaleWidth {0.0};
456     float scaleHeight {0.0};
457     float pitch {0.0};
458     float yaw {0.0};
459     float roll {0.0};
460     float prob {0.0};
461     int32_t albumIdNew {-1};
462     int32_t fileIdNew {-1};
463     int32_t totalFaces {0};
464     std::string hash;
465     std::string faceId;
466     std::string tagIdOld;
467     std::string tagIdNew;
468     std::string landmarks;
469 };
470 
471 struct AnalysisAlbumTbl {
472     std::optional<int32_t> albumId;
473     std::optional<int32_t> albumType;
474     std::optional<int32_t> albumSubtype;
475     std::optional<std::string> albumName;
476     std::optional<std::string> coverUri;
477     std::optional<int32_t> count;
478     std::optional<int64_t> dateModified;
479     std::optional<int32_t> rank;
480     std::optional<std::string> tagId;
481     std::optional<int32_t> userOperation;
482     std::optional<std::string> groupTag;
483     std::optional<int32_t> userDisplayLevel;
484     std::optional<int32_t> isMe;
485     std::optional<int32_t> isRemoved;
486     std::optional<int32_t> renameOperation;
487     std::optional<int32_t> isLocal;
488     std::optional<int32_t> isCoverSatisfied;
489 };
490 
491 struct PortraitAlbumDfx {
492     std::optional<std::string> albumName;
493     std::optional<std::string> coverUri;
494     std::optional<std::string> tagId;
495     std::optional<int32_t> count;
496 };
497 
498 struct FaceTagTbl {
499     std::optional<int32_t> id;
500     std::optional<std::string> tagId;
501     std::optional<std::string> tagName;
502     std::optional<int32_t> userOperation;
503     std::optional<std::string> groupTag;
504     std::optional<int32_t> renameOperation;
505     std::optional<std::string> centerFeatures;
506     std::optional<std::string> tagVersion;
507     std::optional<int32_t> userDisplayLevel;
508     std::optional<int32_t> tagOrder;
509     std::optional<int32_t> isMe;
510     std::optional<std::string> coverUri;
511     std::optional<int32_t> count;
512     std::optional<int64_t> dateModify;
513     std::optional<int32_t> albumType;
514     std::optional<int32_t> isRemoved;
515     std::optional<std::string> analysisVersion;
516 };
517 
518 struct ImageFaceTbl {
519     std::optional<int32_t> id;
520     std::optional<int32_t> fileId;
521     std::optional<std::string> faceId;
522     std::optional<std::string> tagId;
523     std::optional<double> scaleX;
524     std::optional<double> scaleY;
525     std::optional<double> scaleWidth;
526     std::optional<double> scaleHeight;
527     std::optional<std::string> landmarks;
528     std::optional<double> pitch;
529     std::optional<double> yaw;
530     std::optional<double> roll;
531     std::optional<double> prob;
532     std::optional<int32_t> totalFaces;
533     std::optional<std::string> faceVersion;
534     std::optional<std::string> featuresVersion;
535     std::optional<std::string> features;
536     std::optional<int32_t> faceOcclusion;
537     std::optional<std::string> analysisVersion;
538     std::optional<double> beautyBounderX;
539     std::optional<double> beautyBounderY;
540     std::optional<double> beautyBounderWidth;
541     std::optional<double> beautyBounderHeight;
542     std::optional<double> aestheticsScore;
543     std::optional<std::string> beautyBounderVersion;
544     std::optional<int32_t> isExcluded;
545 };
546 
547 struct AnalysisPhotoMapTbl {
548     std::optional<int32_t> mapAlbum;
549     std::optional<int32_t> mapAsset;
550 };
551 
552 using NeedQueryMap = std::unordered_map<PhotoRelatedType, std::unordered_set<std::string>>;
553 
554 // sql for external
555 const std::string QUERY_FILE_COLUMN = "SELECT _id, " + GALLERY_FILE_DATA + ", " + GALLERY_DISPLAY_NAME + ", " +
556     EXTERNAL_IS_FAVORITE + ", " + GALLERY_FILE_SIZE + ", " + GALLERY_DURATION + ", " + GALLERY_MEDIA_TYPE + ", " +
557     EXTERNAL_DATE_MODIFIED + ", " + GALLERY_HEIGHT + ", " + GALLERY_WIDTH + ", " + GALLERY_TITLE + ", " +
558     GALLERY_ORIENTATION + ", " + EXTERNAL_DATE_ADDED + ", " + EXTERNAL_DATE_TAKEN + ", " +
559     GALLERY_SPECIAL_FILE_TYPE + " FROM files WHERE ";
560 
561 const std::string IN_CAMERA = " bucket_id IN (-1739773001, 0, 1028075469, 0) AND (is_pending = 0)";
562 
563 const std::string NOT_IN_CAMERA = " bucket_id NOT IN (-1739773001, 0, 1028075469, 0 ) AND is_pending = 0";
564 
565 const std::string IS_PENDING = " is_pending = 0";
566 
567 const std::string QUERY_NOT_SYNC = " _id < 1000000000 AND media_type IN (1, 3) AND _size > 0 ";
568 
569 const std::string IMAGE_AND_VIDEO_TYPE = " media_type IN (1, 3) AND _size > 0";
570 
571 const std::string GROUP_BY_MEIDA_TYPE = " group by media_type";
572 
573 const std::string COMPARE_ID = " _id > ";
574 
575 const std::string QUERY_COUNT_FROM_FILES = "SELECT count(1) AS count FROM files WHERE";
576 
577 const std::string QUERY_MEDIA_TYPE_AND_COUNT_FROM_FILES = "SELECT media_type,count(1) AS count FROM files WHERE";
578 
579 // sql for gallery
580 const std::string QUERY_GARBAGE_ALBUM = "SELECT type, cache_dir, nick_dir, nick_name FROM garbage_album";
581 
582 const std::string QUERY_MAX_ID_CAMERA_SCREENSHOT = "SELECT max(local_media_id) AS max_id FROM gallery_media \
583     WHERE local_media_id > 0 AND bucket_id IN (-1739773001, 0, 1028075469, 0) AND \
584     (recycleFlag NOT IN (2, -1, 1, -2, -4) OR recycleFlag IS NULL) AND \
585     (storage_id IN (0, 65537) or storage_id IS NULL) AND _size > 0 "; // only in upgrade external
586 
587 const std::string QUERY_MAX_ID_OTHERS = "SELECT max(local_media_id) AS max_id FROM gallery_media \
588     WHERE local_media_id > 0 AND bucket_id NOT IN (-1739773001, 0, 1028075469, 0) AND \
589     (recycleFlag NOT IN (2, -1, 1, -2, -4) OR recycleFlag IS NULL) AND \
590     (storage_id IN (0, 65537) or storage_id IS NULL) AND _size > 0 "; // only in upgrade external
591 
592 const std::string QUERY_MAX_ID_ALL = "SELECT max(local_media_id) AS max_id FROM gallery_media \
593     WHERE local_media_id > 0 AND (recycleFlag NOT IN (2, -1, 1, -2, -4) OR recycleFlag IS NULL) AND \
594     (storage_id IN (0, 65537) or storage_id IS NULL) AND _size > 0 "; // only in upgrade external
595 
596 const std::string ALL_PHOTOS_WHERE_CLAUSE = " (local_media_id != -1) AND (relative_bucket_id IS NULL OR \
597     relative_bucket_id NOT IN (SELECT DISTINCT relative_bucket_id FROM garbage_album WHERE type = 1)) AND _size > 0 \
598     AND _data NOT LIKE '/storage/emulated/0/Pictures/cloud/Imports%' ";
599 
600 const std::string ALL_PHOTOS_ORDER_BY = " ORDER BY showDateToken ASC ";
601 
602 const std::string EXCLUDE_SD = " (storage_id IN (0, 65537)) ";
603 
604 const std::string DUAL_CLONE_AUDIO_FULL_TABLE = "mediainfo INNER JOIN mediafile ON mediainfo." + AUDIO_DATA +
605     " = '/storage/emulated/0'||mediafile.filepath";
606 
607 const std::string QUERY_ALL_AUDIOS_FROM_AUDIODB = "SELECT " + AUDIO_DATA + "," + AUDIO_DATE_MODIFIED + "," +
608     AUDIO_DATE_TAKEN + " FROM " + DUAL_CLONE_AUDIO_FULL_TABLE;
609 
610 const std::string QUERY_DUAL_CLONE_AUDIO_COUNT = "SELECT count(1) as count FROM " + DUAL_CLONE_AUDIO_FULL_TABLE;
611 
612 const std::vector<std::string> EXCLUDED_PORTRAIT_COLUMNS = {"album_id", "count", "rank"};
613 const std::vector<std::string> EXCLUDED_FACE_TAG_COLUMNS = {"id", "user_operation", "rename_operation", "group_tag",
614     "user_display_level", "tag_order", "is_me", "cover_uri", "count", "date_modify", "album_type", "is_removed"};
615 const std::vector<std::string> EXCLUDED_IMAGE_FACE_COLUMNS = {"id"};
616 } // namespace Media
617 } // namespace OHOS
618 
619 #endif  // OHOS_MEDIA_BACKUP_DEFINES_H
620