1 /* 2 * Copyright (c) 2022-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 16 #ifndef FILE_ACCESS_EXT_STUB_IMPL_H 17 #define FILE_ACCESS_EXT_STUB_IMPL_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "file_access_ext_ability.h" 23 #include "file_access_ext_base_stub.h" 24 #include "file_access_extension_info.h" 25 #include "js_native_api_types.h" 26 #include "uri.h" 27 #include "uri_ext.h" 28 29 namespace OHOS { 30 namespace FileAccessFwk { 31 class FileAccessExtStubImpl : public FileAccessExtBaseStub { 32 public: FileAccessExtStubImpl(const std::shared_ptr<FileAccessExtAbility> & extension,napi_env env)33 explicit FileAccessExtStubImpl(const std::shared_ptr<FileAccessExtAbility>& extension, napi_env env) 34 : extension_(extension) {} 35 ~FileAccessExtStubImpl()36 virtual ~FileAccessExtStubImpl() {} 37 38 bool CheckCallingPermission(const std::string &permission); 39 int OpenFile(const Urie &uri, const int flags, int &fd) override; 40 int CreateFile(const Urie &parent, const std::string &displayName, Urie &newFile) override; 41 int Mkdir(const Urie &parent, const std::string &displayName, Urie &newFile) override; 42 int Delete(const Urie &sourceFile) override; 43 int Move(const Urie &sourceFile, const Urie &targetParent, Urie &newFile) override; 44 int Copy(const Urie &sourceUri, const Urie &destUri, std::vector<Result> ©Result, 45 int32_t& retCode, bool force = false) override; 46 int CopyFile(const Urie &sourceUri, const Urie &destUri, const std::string &fileName, 47 Urie &newFileUri) override; 48 int Rename(const Urie &sourceFile, const std::string &displayName, Urie &newFile) override; 49 int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter, 50 SharedMemoryInfo &memInfo) override; 51 int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, 52 const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; 53 int Query(const Urie &uri, const std::vector<std::string> &columns, std::vector<std::string> &results) override; 54 int GetFileInfoFromUri(const Urie &selectFile, FileInfo &fileInfo) override; 55 int GetFileInfoFromRelativePath(const std::string &selectFile, FileInfo &fileInfo) override; 56 int GetRoots(std::vector<RootInfo> &rootInfoVec) override; 57 int Access(const Urie &uri, bool &isExist) override; 58 int StartWatcher(const Urie &uri) override; 59 int StopWatcher(const Urie &uri) override; 60 int MoveItem(const Urie &sourceFile, const Urie &targetParent, std::vector<Result> &moveResult, 61 int32_t& retCode, bool force = false) override; 62 int MoveFile(const Urie &sourceFile, const Urie &targetParent, const std::string &fileName, Urie &newFile) override; 63 private: 64 std::shared_ptr<FileAccessExtAbility> GetOwner(); 65 std::shared_ptr<FileAccessExtAbility> extension_; 66 }; 67 } // namespace FileAccessFwk 68 } // namespace OHOS 69 #endif // FILE_ACCESS_EXT_STUB_IMPL_H 70