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