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 16 #ifndef FILE_ACCESS_EXT_ABILITY_H 17 #define FILE_ACCESS_EXT_ABILITY_H 18 19 #include "extension_base.h" 20 #include "file_access_extension_info.h" 21 #include "file_access_notify_manager.h" 22 #include "file_filter.h" 23 24 namespace OHOS { 25 namespace AbilityRuntime { 26 class Runtime; 27 } 28 namespace FileAccessFwk { 29 using namespace DistributedFS; 30 using namespace AbilityRuntime; 31 class FileAccessExtAbility; 32 using CreatorFunc = std::function<FileAccessExtAbility* (const std::unique_ptr<Runtime>& runtime)>; 33 class FileAccessExtAbility : public ExtensionBase<> { 34 public: 35 FileAccessExtAbility() = default; 36 virtual ~FileAccessExtAbility() = default; 37 38 virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record, 39 const std::shared_ptr<OHOSApplication> &application, 40 std::shared_ptr<AbilityHandler> &handler, 41 const sptr<IRemoteObject> &token) override; 42 43 static FileAccessExtAbility* Create(const std::unique_ptr<Runtime>& runtime); 44 45 virtual int OpenFile(const Uri &uri, const int flags, int &fd); 46 virtual int CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile); 47 virtual int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile); 48 virtual int Delete(const Uri &sourceFile); 49 virtual int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile); 50 virtual int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile); 51 virtual int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, 52 const FileFilter &filter, std::vector<FileInfo> &fileInfoVec); 53 virtual int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, 54 const FileFilter &filter, std::vector<FileInfo> &fileInfoVec); 55 virtual int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo); 56 virtual int GetRoots(std::vector<RootInfo> &rootInfoVec); 57 virtual int Access(const Uri &uri, bool &isExist); 58 virtual int RegisterNotify(sptr<IFileAccessNotify> ¬ify); 59 virtual int UnregisterNotify(sptr<IFileAccessNotify> ¬ify); 60 virtual int Notify(const NotifyMessage &message); 61 static void SetCreator(const CreatorFunc& creator); 62 private: 63 bool GetNotifyManager(); 64 static CreatorFunc creator_; 65 std::unique_ptr<FileAccessNotifyManager> notifyManager_; 66 }; 67 } // namespace FileAccessFwk 68 } // namespace OHOS 69 #endif // FILE_ACCESS_EXT_ABILITY_H