1 /* 2 * Copyright (c) 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 #ifndef INTERFACES_KITS_CJ_PICKER_H 16 #define INTERFACES_KITS_CJ_PICKER_H 17 18 #include <cstdint> 19 #include <dirent.h> 20 #include <thread> 21 #include <string> 22 #include "cj_lambda.h" 23 #include "cj_common_ffi.h" 24 #include "context.h" 25 #include "data_ability_helper.h" 26 #include "data_ability_observer_stub.h" 27 #include "data_ability_predicates.h" 28 #include "filemgmt_libn.h" 29 #include "ui_extension_context.h" 30 #include "ability_context.h" 31 #include "want.h" 32 #include "want_params.h" 33 #include "ui_content.h" 34 #include "hilog_wrapper.h" 35 36 namespace OHOS { 37 namespace CjPicker { 38 39 using WantHandle = void*; 40 static sptr<Rosen::Window> window_; 41 42 struct CjPickerCallBack { 43 bool ready = false; 44 int32_t resultCode; 45 OHOS::AAFwk::Want want; 46 }; 47 48 extern "C" { 49 struct PickerResult { 50 int32_t resultCode; 51 int32_t userSuffixIndex; 52 bool isOriginal; 53 CArrString ability_params_stream; 54 CArrString uriArr; 55 CArrString photoUris; 56 }; 57 58 FFI_EXPORT int32_t FfiOHOSFilePickerModalPicker(OHOS::AbilityRuntime::Context* context, 59 WantHandle config, char* windowName, void (*callback)(PickerResult)); 60 } 61 62 class CjModalUICallback { 63 public: 64 explicit CjModalUICallback(Ace::UIContent* uiContent, 65 std::shared_ptr<CjPickerCallBack> pickerCallBack, void (*callback)(PickerResult)); 66 void OnRelease(int32_t releaseCode); 67 void OnResultForModal(int32_t resultCode, const OHOS::AAFwk::Want& result); 68 void OnReceive(const OHOS::AAFwk::WantParams& request); 69 void OnError(int32_t code, const std::string& name, const std::string& message); 70 void OnDestroy(); 71 void SetSessionId(int32_t sessionId); 72 73 private: 74 int32_t sessionId_ = 0; 75 std::function<void(PickerResult)> callback{nullptr}; 76 Ace::UIContent* uiContent; 77 std::shared_ptr<CjPickerCallBack> pickerCallBack_; 78 }; 79 80 } // namespace CjPicker 81 } // namespace OHOS 82 83 #endif // INTERFACES_KITS_CJ_PICKER_H