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 #include "medialibrary_type_const.h" 26 #include "media_scanner_const.h" 27 #include "shooting_mode_column.h" 28 29 namespace OHOS { 30 namespace Media { 31 #define EXPORT __attribute__ ((visibility ("default"))) 32 enum EXPORT ErrorCodes { 33 ERR_FAIL = -1, 34 ERR_SUCCESS, 35 ERR_EMPTY_ARGS, 36 ERR_NOT_ACCESSIBLE, 37 ERR_INCORRECT_PATH, 38 ERR_MEM_ALLOC_FAIL, 39 ERR_MIMETYPE_NOTSUPPORT, 40 ERR_SCAN_NOT_INIT 41 }; 42 43 constexpr int32_t MAX_BATCH_SIZE = 5; 44 45 constexpr int32_t UNKNOWN_ID = -1; 46 47 // Const for File Metadata defaults 48 const std::string FILE_PATH_DEFAULT = ""; 49 const std::string FILE_NAME_DEFAULT = ""; 50 const int64_t FILE_SIZE_DEFAULT = 0; 51 const std::string URI_DEFAULT = ""; 52 const int64_t FILE_DATE_ADDED_DEFAULT = 0; 53 const int64_t FILE_DATE_MODIFIED_DEFAULT = 0; 54 const MediaType FILE_MEDIA_TYPE_DEFAULT = MEDIA_TYPE_FILE; 55 const int32_t FILE_ID_DEFAULT = 0; 56 const std::string FILE_EXTENSION_DEFAULT = ""; 57 58 const int32_t FILE_DURATION_DEFAULT = 0; 59 const std::string FILE_TITLE_DEFAULT = ""; 60 const std::string FILE_ARTIST_DEFAULT = ""; 61 const int32_t FILE_HEIGHT_DEFAULT = 0; 62 const int32_t FILE_WIDTH_DEFAULT = 0; 63 const int32_t FILE_ALBUM_ID_DEFAULT = 0; 64 const std::string FILE_ALBUM_NAME_DEFAULT = ""; 65 const int32_t FILE_ORIENTATION_DEFAULT = 0; 66 const std::string FILE_SHOOTINGMODE_DEFAULT = ""; 67 const std::string FILE_RELATIVE_PATH_DEFAULT = ""; 68 const std::string FILE_RECYCLE_PATH_DEFAULT = ""; 69 const int64_t FILE_DATE_TAKEN_DEFAULT = 0; 70 const double FILE_LONGITUDE_DEFAULT = 0; 71 const double FILE_LATITUDE_DEFAULT = 0; 72 const int64_t FILE_TIME_PENDING_DEFAULT = 0; 73 const std::string FILE_All_EXIF_DEFAULT = ""; 74 const std::string FILE_USER_COMMENT_DEFAULT = ""; 75 const int64_t FILE_LAST_VISIT_TIME_DEFAULT = 0; 76 77 const std::string DEFAULT_AUDIO_MIME_TYPE = "audio/*"; 78 const std::string DEFAULT_VIDEO_MIME_TYPE = "video/*"; 79 const std::string DEFAULT_IMAGE_MIME_TYPE = "image/*"; 80 const std::string DEFAULT_FILE_MIME_TYPE = "file/*"; 81 82 static std::vector<std::string> EXTRACTOR_SUPPORTED_MIME = { 83 DEFAULT_AUDIO_MIME_TYPE, 84 DEFAULT_VIDEO_MIME_TYPE, 85 DEFAULT_IMAGE_MIME_TYPE 86 }; 87 88 static const std::unordered_map<std::string, std::string> SHOOTING_MODE_CAST_MAP = { 89 {PORTRAIT_ALBUM_TAG, PORTRAIT_ALBUM}, 90 {WIDE_APERTURE_ALBUM_TAG, WIDE_APERTURE_ALBUM}, 91 {NIGHT_SHOT_ALBUM_TAG, NIGHT_SHOT_ALBUM}, 92 {REAR_CAMERA_NIGHT_SHOT_TAG, NIGHT_SHOT_ALBUM}, 93 {MOVING_PICTURE_ALBUM_TAG, MOVING_PICTURE_ALBUM}, 94 {PRO_PHOTO_ALBUM_TAG, PRO_PHOTO_ALBUM}, 95 {TAIL_LIGHT_ALBUM_TAG, LIGHT_PAINTING_ALBUM}, 96 {LIGHT_GRAFFITI_TAG, LIGHT_PAINTING_ALBUM}, 97 {SILKY_WATER_TAG, LIGHT_PAINTING_ALBUM}, 98 {STAR_TRACK_TAG, LIGHT_PAINTING_ALBUM}, 99 {HIGH_PIXEL_ALBUM_TAG, HIGH_PIXEL_ALBUM}, 100 {SUPER_MACRO_ALBUM_TAG, SUPER_MACRO_ALBUM}, 101 {SLOW_MOTION_ALBUM_TAG, SLOW_MOTION_ALBUM}, 102 {SUPER_SLOW_MOTION_ALBUM_TAG, SLOW_MOTION_ALBUM}, 103 }; 104 105 static const std::unordered_map<std::string, std::string> SUPPORTED_EXTN_MAP = { 106 /** Supported image types */ 107 {IMAGE_CONTAINER_TYPE_BMP, DEFAULT_IMAGE_MIME_TYPE}, 108 {IMAGE_CONTAINER_TYPE_BM, DEFAULT_IMAGE_MIME_TYPE}, 109 {IMAGE_CONTAINER_TYPE_GIF, DEFAULT_IMAGE_MIME_TYPE}, 110 {IMAGE_CONTAINER_TYPE_JPG, DEFAULT_IMAGE_MIME_TYPE}, 111 {IMAGE_CONTAINER_TYPE_JPEG, DEFAULT_IMAGE_MIME_TYPE}, 112 {IMAGE_CONTAINER_TYPE_JPE, DEFAULT_IMAGE_MIME_TYPE}, 113 {IMAGE_CONTAINER_TYPE_PNG, DEFAULT_IMAGE_MIME_TYPE}, 114 {IMAGE_CONTAINER_TYPE_WEBP, DEFAULT_IMAGE_MIME_TYPE}, 115 {IMAGE_CONTAINER_TYPE_RAW, DEFAULT_IMAGE_MIME_TYPE}, 116 {IMAGE_CONTAINER_TYPE_SVG, DEFAULT_IMAGE_MIME_TYPE}, 117 {IMAGE_CONTAINER_TYPE_HEIF, DEFAULT_IMAGE_MIME_TYPE}, 118 /** Supported video container types */ 119 {VIDEO_CONTAINER_TYPE_MP4, DEFAULT_VIDEO_MIME_TYPE}, 120 {VIDEO_CONTAINER_TYPE_3GP, DEFAULT_VIDEO_MIME_TYPE}, 121 {VIDEO_CONTAINER_TYPE_MPG, DEFAULT_VIDEO_MIME_TYPE}, 122 {VIDEO_CONTAINER_TYPE_MOV, DEFAULT_VIDEO_MIME_TYPE}, 123 {VIDEO_CONTAINER_TYPE_WEBM, DEFAULT_VIDEO_MIME_TYPE}, 124 {VIDEO_CONTAINER_TYPE_MKV, DEFAULT_VIDEO_MIME_TYPE}, 125 {AUDIO_CONTAINER_TYPE_AAC, DEFAULT_AUDIO_MIME_TYPE}, 126 {AUDIO_CONTAINER_TYPE_MP3, DEFAULT_AUDIO_MIME_TYPE}, 127 {AUDIO_CONTAINER_TYPE_FLAC, DEFAULT_AUDIO_MIME_TYPE}, 128 {AUDIO_CONTAINER_TYPE_WAV, DEFAULT_AUDIO_MIME_TYPE}, 129 {AUDIO_CONTAINER_TYPE_OGG, DEFAULT_AUDIO_MIME_TYPE}, 130 {"7z", "application/x-7z-compressed"}, 131 {"bz", "application/x-bzip"}, 132 {"bz2", "application/x-bzip2"}, 133 {"cer", "application/pkix-cert"}, 134 {"clp", "application/x-msclip"}, 135 {"crl", "application/pkix-crl"}, 136 {"css", "text/css"}, 137 {"csv", "text/csv"}, 138 {"der", "application/x-x509-ca-cert"}, 139 {"doc", "application/msword"}, 140 {"docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, 141 {"exe", "application/x-msdownload"}, 142 {"gtar", "application/x-gtar"}, 143 {"gz", "application/gzip"}, 144 {"html", "text/html"}, 145 {"ics", "text/calendar"}, 146 {"ipfix", "application/ipfix"}, 147 {"jar", "application/java-archive"}, 148 {"json", "application/json"}, 149 {"mdb", "application/x-msaccess"}, 150 {"nsf", "application/vnd.lotus-notes"}, 151 {"odb", "application/vnd.oasis.opendocument.database"}, 152 {"odc", "application/vnd.oasis.opendocument.chart"}, 153 {"odp", "application/vnd.oasis.opendocument.presentation"}, 154 {"ods", "application/vnd.oasis.opendocument.spreadsheet"}, 155 {"odt", "application/vnd.oasis.opendocument.text"}, 156 {"p10", "application/pkcs10"}, 157 {"p12", "application/x-pkcs12"}, 158 {"p7b", "application/x-pkcs7-certificates"}, 159 {"p7m", "application/pkcs7-mime"}, 160 {"p7r", "application/x-pkcs7-certreqresp"}, 161 {"p7s", "application/pkcs7-signature"}, 162 {"p8", "application/pkcs8"}, 163 {"pdf", "application/pdf"}, 164 {"pki", "application/pkixcmp"}, 165 {"pkipath", "application/pkix-pkipath"}, 166 {"ppt", "application/vnd.ms-powerpoint"}, 167 {"pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, 168 {"rar", "application/x-rar-compressed"}, 169 {"rss", "application/rss+xml"}, 170 {"rtf", "application/rtf"}, 171 {"rtx", "text/richtext"}, 172 {"sxc", "application/vnd.sun.xml.calc"}, 173 {"sxg", "application/vnd.sun.xml.writer.global"}, 174 {"sxi", "application/vnd.sun.xml.impress"}, 175 {"sxw", "application/vnd.sun.xml.writer"}, 176 {"tar", "application/x-tar"}, 177 {"texinfo", "application/x-texinfo"}, 178 {"torrent", "application/x-bittorrent"}, 179 {"txt", "text/plain"}, 180 {"vcf", "text/x-vcard"}, 181 {"vcs", "text/x-vcalendar"}, 182 {"vsd", "application/vnd.visio"}, 183 {"vsdx", "application/vnd.visio2013"}, 184 {"vxml", "application/voicexml+xml"}, 185 {"wml", "text/vnd.wap.wml"}, 186 {"wmls", "text/vnd.wap.wmlscript"}, 187 {"wps", "application/vnd.ms-works"}, 188 {"wri", "application/x-mswrite"}, 189 {"xdf", "application/xcap-diff+xml"}, 190 {"xhtml", "application/xhtml+xml"}, 191 {"xls", "application/vnd.ms-excel"}, 192 {"xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, 193 {"xml", "application/xml"}, 194 {"xps", "application/vnd.ms-xpsdocument"}, 195 {"yaml", "text/yaml"}, 196 {"zip", "application/zip"}, 197 }; 198 199 class ScannerUtils { 200 public: 201 EXPORT ScannerUtils(); 202 EXPORT ~ScannerUtils(); 203 204 EXPORT static bool IsExists(const std::string &path); 205 EXPORT static std::string GetFileNameFromUri(const std::string &path); 206 EXPORT static std::string GetFileExtension(const std::string &path); 207 EXPORT static std::string GetParentPath(const std::string &path); 208 EXPORT static bool IsFileHidden(const std::string &path); 209 EXPORT static bool IsDirectory(const std::string &path); 210 EXPORT static bool IsRegularFile(const std::string &path); 211 EXPORT static void GetRootMediaDir(std::string &dir); 212 EXPORT static std::string GetFileTitle(const std::string &displayName); 213 EXPORT static bool IsDirHiddenRecursive(const std::string &path, bool skipPhoto = true); 214 EXPORT static bool IsDirHidden(const std::string &path, bool skipPhoto = true); 215 EXPORT static bool CheckSkipScanList(const std::string &path); 216 }; 217 } // namespace Media 218 } // namespace OHOS 219 220 #endif // SCANNER_UTILS_H 221