1 /* 2 * Copyright (C) 2021 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 SCANNER_UTILS_H 17 #define SCANNER_UTILS_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <unordered_set> 22 #include <vector> 23 #include <sys/stat.h> 24 25 namespace OHOS { 26 namespace Media { 27 #define EXPORT __attribute__ ((visibility ("default"))) 28 enum EXPORT ErrorCodes { 29 ERR_FAIL = -1, 30 ERR_SUCCESS, 31 ERR_EMPTY_ARGS, 32 ERR_NOT_ACCESSIBLE, 33 ERR_INCORRECT_PATH, 34 ERR_MEM_ALLOC_FAIL, 35 ERR_MIMETYPE_NOTSUPPORT, 36 ERR_SCAN_NOT_INIT 37 }; 38 39 constexpr int32_t MAX_BATCH_SIZE = 5; 40 41 constexpr int32_t UNKNOWN_ID = -1; 42 43 // Const for File Metadata defaults 44 const std::string FILE_PATH_DEFAULT = ""; 45 const std::string FILE_NAME_DEFAULT = ""; 46 const int64_t FILE_SIZE_DEFAULT = 0; 47 const std::string URI_DEFAULT = ""; 48 const int64_t FILE_DATE_ADDED_DEFAULT = 0; 49 const int64_t FILE_DATE_MODIFIED_DEFAULT = 0; 50 const int32_t FILE_ID_DEFAULT = 0; 51 const std::string FILE_EXTENSION_DEFAULT = ""; 52 53 const int32_t FILE_DURATION_DEFAULT = 0; 54 const std::string FILE_TITLE_DEFAULT = ""; 55 const std::string FILE_ARTIST_DEFAULT = ""; 56 const int32_t FILE_HEIGHT_DEFAULT = 0; 57 const int32_t FILE_WIDTH_DEFAULT = 0; 58 const int32_t FILE_ALBUM_ID_DEFAULT = 0; 59 const std::string FILE_ALBUM_NAME_DEFAULT = ""; 60 const int32_t FILE_ORIENTATION_DEFAULT = 0; 61 const std::string FILE_SHOOTINGMODE_DEFAULT = ""; 62 const std::string FILE_RELATIVE_PATH_DEFAULT = ""; 63 const std::string FILE_RECYCLE_PATH_DEFAULT = ""; 64 const int64_t FILE_DATE_TAKEN_DEFAULT = 0; 65 const double FILE_LONGITUDE_DEFAULT = 0; 66 const double FILE_LATITUDE_DEFAULT = 0; 67 const int64_t FILE_TIME_PENDING_DEFAULT = 0; 68 const std::string FILE_All_EXIF_DEFAULT = ""; 69 const std::string FILE_USER_COMMENT_DEFAULT = ""; 70 const int64_t FILE_LAST_VISIT_TIME_DEFAULT = 0; 71 const int32_t FILE_DYNAMIC_RANGE_TYPE_DEFAULT = 0; 72 const int32_t FILE_IS_TEMP_DEFAULT = 0; 73 const std::string FILE_FRONT_CAMERA_DEFAULT = ""; 74 const std::string FILE_DETAIL_TIME_DEFAULT = ""; 75 const int32_t COVER = 1; 76 const int32_t BURST_COVER_LEVEL_DEFAULT = COVER; 77 const int32_t STAGE_VIDEO_TASK_STATUS = 0; 78 79 const std::string DEFAULT_AUDIO_MIME_TYPE = "audio/*"; 80 const std::string DEFAULT_VIDEO_MIME_TYPE = "video/*"; 81 const std::string DEFAULT_IMAGE_MIME_TYPE = "image/*"; 82 const std::string DEFAULT_FILE_MIME_TYPE = "file/*"; 83 84 static std::vector<std::string> EXTRACTOR_SUPPORTED_MIME = { 85 DEFAULT_AUDIO_MIME_TYPE, 86 DEFAULT_VIDEO_MIME_TYPE, 87 DEFAULT_IMAGE_MIME_TYPE 88 }; 89 90 class ScannerUtils { 91 public: 92 EXPORT ScannerUtils(); 93 EXPORT ~ScannerUtils(); 94 95 EXPORT static bool IsExists(const std::string &path); 96 EXPORT static std::string GetFileNameFromUri(const std::string &path); 97 EXPORT static std::string GetFileExtension(const std::string &path); 98 EXPORT static std::string GetParentPath(const std::string &path); 99 EXPORT static bool IsFileHidden(const std::string &path); 100 EXPORT static bool IsDirectory(const std::string &path); 101 EXPORT static bool IsRegularFile(const std::string &path); 102 EXPORT static void GetRootMediaDir(std::string &dir); 103 EXPORT static std::string GetFileTitle(const std::string &displayName); 104 EXPORT static bool IsDirHiddenRecursive(const std::string &path, bool skipPhoto = true); 105 EXPORT static bool IsDirHidden(const std::string &path, bool skipPhoto = true); 106 EXPORT static bool CheckSkipScanList(const std::string &path); 107 }; 108 } // namespace Media 109 } // namespace OHOS 110 111 #endif // SCANNER_UTILS_H 112