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