1 /* 2 * Copyright (C) 2022 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 #ifndef FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 17 #include <memory> 18 #include <vector> 19 #include <string> 20 #include <variant> 21 #include <sys/time.h> 22 #include <stdio.h> 23 24 #include "datashare_result_set.h" 25 #include "mtp_operation_context.h" 26 #include "property.h" 27 #include "userfile_manager_types.h" 28 #include "result_set_utils.h" 29 30 namespace OHOS { 31 namespace Media { 32 struct PropertyValue { 33 uint64_t outIntVal = 0; 34 uint128_t outLongVal = {0}; 35 std::string outStrVal; 36 }; 37 const std::string MTP_FORMAT_ALL = ".all"; // Undefined 38 const std::string MTP_FORMAT_UNDEFINED = ".undefined"; // Undefined 39 const std::string MTP_FORMAT_ASSOCIATION = ".floader"; // associations (folders and directories) 40 const std::string MTP_FORMAT_SCRIPT = ".js"; // script files 41 const std::string MTP_FORMAT_EXECUTABLE = ".exe"; // executable files 42 const std::string MTP_FORMAT_TEXT = ".txt"; // text files 43 const std::string MTP_FORMAT_HTML = ".html"; // HTML files 44 const std::string MTP_FORMAT_DPOF = ".dp"; // DPOF files 45 const std::string MTP_FORMAT_AIFF = ".aiff"; // AIFF audio files 46 const std::string MTP_FORMAT_WAV = ".wav"; // WAV audio files 47 const std::string MTP_FORMAT_MP3 = ".mp3"; // MP3 audio files 48 const std::string MTP_FORMAT_AVI = ".avi"; // AVI video files 49 const std::string MTP_FORMAT_MPEG = ".mpeg"; // MPEG video files 50 const std::string MTP_FORMAT_ASF = ".asf"; // ASF files 51 // Unknown image files which are not specified in PTP specification 52 const std::string MTP_FORMAT_DEFINED = ".image"; // Unknown image files 53 const std::string MTP_FORMAT_EXIF_JPEG = ".jpeg?.jpg"; // JPEG image files 54 const std::string MTP_FORMAT_TIFF_EP = ".tiff"; // TIFF EP image files 55 const std::string MTP_FORMAT_FLASHPIX = ".swf"; 56 const std::string MTP_FORMAT_BMP = ".bmp"; // BMP image files 57 const std::string MTP_FORMAT_CIFF = ".ciff"; 58 const std::string MTP_FORMAT_GIF = ".giff"; // GIF image files 59 const std::string MTP_FORMAT_JFIF = ".jsif"; // JFIF image files 60 const std::string MTP_FORMAT_CD = ".cd"; 61 const std::string MTP_FORMAT_PICT = ".pict"; // PICT image files 62 const std::string MTP_FORMAT_PNG = ".png"; // PNG image files 63 const std::string MTP_FORMAT_TIFF = ".tif"; // TIFF image files 64 const std::string MTP_FORMAT_TIFF_IT = ".tiff"; 65 const std::string MTP_FORMAT_JP2 = ".jp2"; // JP2 files 66 const std::string MTP_FORMAT_JPX = ".jpx"; // JPX files 67 const std::string MTP_FORMAT_UNDEFINED_FIRMWARE = ".undefinedfirmware"; // firmware files 68 const std::string MTP_FORMAT_WINDOWS_IMAGE_FORMAT = ".img"; // Windows image files 69 const std::string MTP_FORMAT_UNDEFINED_AUDIO = ".undefinedaudio"; // undefined audio files files 70 const std::string MTP_FORMAT_WMA = ".wma"; // WMA audio files 71 const std::string MTP_FORMAT_OGG = ".ogg"; // OGG audio files 72 const std::string MTP_FORMAT_AAC = ".aac"; // AAC audio files 73 const std::string MTP_FORMAT_AUDIBLE = ".aa"; // Audible audio files 74 const std::string MTP_FORMAT_FLAC = ".flac"; // FLAC audio files 75 const std::string MTP_FORMAT_UNDEFINED_VIDEO = ".undefinedvideo"; // undefined video files 76 const std::string MTP_FORMAT_WMV = ".wmv"; // WMV video files 77 const std::string MTP_FORMAT_MP4_CONTAINER = ".mp4"; // MP4 files 78 const std::string MTP_FORMAT_MP2 = ".mp2"; // MP2 files 79 const std::string MTP_FORMAT_3GP_CONTAINER = ".3gp"; // 3GP files 80 81 const std::string MTP_FORMAT_UNDEFINED_COLLECTION = ".undefinedcollections"; // undefined collections 82 const std::string MTP_FORMAT_ABSTRACT_MULTIMEDIA_ALBUM = ".album"; // multimedia albums 83 const std::string MTP_FORMAT_ABSTRACT_IMAGE_ALBUM = ".albumimage"; // image albums 84 const std::string MTP_FORMAT_ABSTRACT_AUDIO_ALBUM = ".albumaudio"; // audio albums 85 const std::string MTP_FORMAT_ABSTRACT_VIDEO_ALBUM = ".albumvideo"; // video albums 86 const std::string MTP_FORMAT_ABSTRACT_AUDIO_VIDEO_PLAYLIST = ""; // abstract AV playlists 87 const std::string MTP_FORMAT_ABSTRACT_CONTACT_GROUP = ""; 88 const std::string MTP_FORMAT_ABSTRACT_MESSAGE_FOLDER = ".mesfloader"; 89 const std::string MTP_FORMAT_ABSTRACT_CHAPTERED_PRODUCTION = ""; 90 const std::string MTP_FORMAT_ABSTRACT_AUDIO_PLAYLIST = ".allaudio"; // abstract audio playlists 91 const std::string MTP_FORMAT_ABSTRACT_VIDEO_PLAYLIST = ".allvideo"; // abstract video playlists 92 const std::string MTP_FORMAT_ABSTRACT_MEDIACAST = ""; // abstract mediacasts 93 const std::string MTP_FORMAT_WPL_PLAYLIST = ".wpl"; // WPL playlist files 94 const std::string MTP_FORMAT_M3U_PLAYLIST = ".m3u"; // M3u playlist files 95 const std::string MTP_FORMAT_MPL_PLAYLIST = ".mpl"; // MPL playlist files 96 const std::string MTP_FORMAT_ASX_PLAYLIST = ".asx"; // ASX playlist files 97 const std::string MTP_FORMAT_PLS_PLAYLIST = ".pls"; // PLS playlist files 98 const std::string MTP_FORMAT_UNDEFINED_DOCUMENT = ".undefineddocument"; // undefined document files 99 const std::string MTP_FORMAT_ABSTRACT_DOCUMENT = ".alldocuments"; // abstract documents 100 const std::string MTP_FORMAT_XML_DOCUMENT = ".xml"; // XML documents 101 const std::string MTP_FORMAT_MICROSOFT_WORD_DOCUMENT = ".doc"; // MS Word documents 102 const std::string MTP_FORMAT_MHT_COMPILED_HTML_DOCUMENT = ".html"; 103 const std::string MTP_FORMAT_MICROSOFT_EXCEL_SPREADSHEET = ""; // MS Excel spreadsheets 104 const std::string MTP_FORMAT_MICROSOFT_POWERPOINT_PRESENTATION = ""; // MS PowerPoint presentatiosn 105 const std::string MTP_FORMAT_UNDEFINED_MESSAGE = ""; 106 const std::string MTP_FORMAT_ABSTRACT_MESSAGE = ""; 107 const std::string MTP_FORMAT_UNDEFINED_CONTACT = ""; 108 const std::string MTP_FORMAT_ABSTRACT_CONTACT = ""; 109 const std::string MTP_FORMAT_VCARD_2 = ""; 110 111 class MtpDataUtils { 112 public: 113 static int32_t SolveHandlesFormatData(const uint16_t format, std::string &outExtension, MediaType &outMediaType); 114 static int32_t SolveSendObjectFormatData(const uint16_t format, MediaType &outMediaType); 115 static int32_t SolveSetObjectPropValueData(const std::shared_ptr<MtpOperationContext> &context, 116 std::string &outColName, std::variant<int64_t, std::string> &outColVal); 117 static void GetMediaTypeByformat(const uint16_t format, MediaType &outMediaType); 118 static void GetPropGropByMediaType(const MediaType &mediaType, std::vector<std::string> &outPropGrop); 119 static int32_t GetPropListBySet(const uint32_t property, 120 const uint16_t format, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 121 std::shared_ptr<std::vector<Property>> &outProps); 122 static int32_t GetPropValueBySet(const uint32_t property, 123 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 124 PropertyValue &outPropValue); 125 static int32_t GetMediaTypeByName(std::string &displayName, MediaType &outMediaType); 126 private: 127 static int32_t GetPropList(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 128 const std::shared_ptr<UInt16List> &properties, std::shared_ptr<std::vector<Property>> &outProps); 129 static void GetFormatByPath(const std::string &path, uint16_t &outFormat); 130 static std::variant<int32_t, int64_t, std::string> ReturnError(const std::string &errMsg, 131 const ResultSetDataType &type); 132 static int32_t GetFormat(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, uint16_t &outFormat); 133 static void GetOneRowPropList(uint32_t handle, const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 134 const std::shared_ptr<UInt16List> &properties, std::shared_ptr<std::vector<Property>> &outProps); 135 static void GetOneRowPropVal(const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, 136 const uint32_t property, PropertyValue &outPropValue); 137 static void SetOneDefaultlPropList(uint32_t handle, 138 uint16_t property, std::shared_ptr<std::vector<Property>> &outProps); 139 static void SetProperty(const std::string &column, 140 const std::shared_ptr<DataShare::DataShareResultSet> &resultSet, ResultSetDataType &type, Property &prop); 141 }; 142 } // namespace Media 143 } // namespace OHOS 144 #endif // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_DATA_UTILS_H_ 145