1 /* 2 * Copyright (c) 2024 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 PHOTO_ACCESS_HELPER_UTILS_H 17 #define PHOTO_ACCESS_HELPER_UTILS_H 18 19 #include <cstdint> 20 #include <memory> 21 #include <string> 22 23 #include "cj_common_ffi.h" 24 #include "cj_data_ffi.h" 25 #include "data_share_predicates_impl.h" 26 #include "datashare_predicates.h" 27 #include "datashare_result_set.h" 28 #include "ffi_remote_data.h" 29 #include "photo_accesshelper_log.h" 30 #include "media_file_uri.h" 31 #include "media_file_utils.h" 32 #include "medialibrary_client_errno.h" 33 #include "medialibrary_napi_utils.h" 34 #include "medialibrary_type_const.h" 35 #include "userfile_client.h" 36 #include "userfile_manager_types.h" 37 38 namespace OHOS { 39 namespace Media { 40 extern "C" { 41 enum FfiListenerType { 42 CJ_INVALID_LISTENER = -1, 43 CJ_AUDIO_LISTENER, 44 CJ_VIDEO_LISTENER, 45 CJ_IMAGE_LISTENER, 46 CJ_FILE_LISTENER, 47 CJ_SMARTCJ_ALBUM_LISTENER, 48 CJ_DEVICE_LISTENER, 49 CJ_REMOTECJ_FILE_LISTENER, 50 CJ_ALBUM_LISTENER 51 }; 52 53 enum class ReturnDataType { 54 TYPE_IMAGE_SOURCE = 0, 55 TYPE_ARRAY_BUFFER, 56 TYPE_MOVING_PHOTO, 57 TYPE_TARGET_PATH, 58 TYPE_PICTURE, 59 }; 60 61 enum class DeliveryMode { 62 FAST = 0, 63 HIGH_QUALITY, 64 BALANCED_MODE, 65 }; 66 67 enum class SourceMode { 68 ORIGINAL_MODE = 0, 69 EDITED_MODE, 70 }; 71 72 enum class SingleSelectionMode { 73 BROWSER_MODE = 0, 74 SELECT_MODE, 75 BROWSER_AND_SELECT_MODE, 76 }; 77 78 struct CSize { 79 int32_t width = 0; 80 int32_t height = 0; 81 }; 82 83 struct PhotoAssetMember { 84 int32_t memberType; 85 int64_t intValue; 86 char* stringValue; 87 bool boolValue; 88 }; 89 90 struct FetchResultObject { 91 int64_t id; 92 int32_t fetchResType; 93 }; 94 95 struct CArrayFetchResultObject { 96 FetchResultObject* head; 97 int64_t size; 98 }; 99 100 struct COptions { 101 CArrString fetchColumns; 102 int64_t predicates; 103 }; 104 105 struct CreateOptions { 106 char* title; 107 int32_t subtype; 108 }; 109 110 struct ChangeData { 111 int32_t type; 112 CArrString uris; 113 CArrString extraUris; 114 }; 115 116 struct PhotoCreationConfig { 117 char* title; 118 char* fileNameExtension; 119 int32_t photoType; 120 int32_t subtype; 121 }; 122 123 struct PhotoCreationConfigs { 124 PhotoCreationConfig* head; 125 int64_t size; 126 }; 127 128 struct FfiBundleInfo { 129 char* bundleName; 130 char* appName; 131 char* appId; 132 }; 133 134 struct TextContextInfo { 135 char* text; 136 }; 137 138 struct RecommendationOptions { 139 int32_t recommendationType; 140 TextContextInfo textContextInfo; 141 }; 142 143 struct PhotoSelectOptions { 144 int32_t MIMEType; 145 int32_t maxSelectNumber; 146 bool isPhotoTakingSupported; 147 bool isSearchSupported; 148 RecommendationOptions recommendationOptions; 149 CArrString preselectedUris; 150 bool isPreviewForSingleSelectionSupported; 151 SingleSelectionMode singleSelectionMode; 152 bool isEditSupported; 153 bool isOriginalSupported; 154 char* subWindowName; 155 }; 156 157 struct PhotoSelectResult { 158 CArrString photoUris; 159 bool isOriginalPhoto; 160 }; 161 162 struct RequestOptions { 163 int32_t deliveryMode; 164 }; 165 166 struct KeyValue { 167 char* key; 168 char* value; 169 }; 170 171 struct HashMapArray { 172 KeyValue* head; 173 int64_t size; 174 }; 175 176 struct MediaObject { 177 ReturnDataType returnDataType; 178 CArrUI8 imageData; 179 int64_t imageId = -1; 180 int64_t movingPhotoId = -1; 181 bool videoFile = false; 182 }; 183 184 struct ExtraInfo { 185 FetchOptionType fetchOptType; 186 std::string networkId; 187 std::string uri; 188 }; 189 } 190 191 struct PickerCallBack { 192 bool ready = false; 193 bool isOrigin; 194 int32_t resultCode; 195 std::vector<std::string> uris; 196 }; 197 198 char *MallocCString(const std::string &origin); 199 bool GetPredicate(COptions options, DataShare::DataSharePredicates &predicates, 200 std::vector<std::string> &fetchColumn, ExtraInfo &extraInfo, int32_t &errCode); 201 void GetFetchOption(COptions options, DataShare::DataSharePredicates &predicates, 202 std::vector<std::string> &fetchColumn, ExtraInfo &extraInfo, int32_t &errCode); 203 void AddDefaultAssetColumns(std::vector<std::string> &fetchColumn, 204 std::function<bool(const std::string &columnName)> isValidColumn, NapiAssetType assetType, 205 int32_t &errCode, const PhotoAlbumSubType subType = PhotoAlbumSubType::USER_GENERIC); 206 } 207 } 208 #endif