1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specic language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MEDIAPROVIDER_JNI_FUSEDAEMON_H_ 18 #define MEDIAPROVIDER_JNI_FUSEDAEMON_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include <android-base/unique_fd.h> 24 25 #include "MediaProviderWrapper.h" 26 #include "jni.h" 27 28 struct fuse; 29 namespace mediaprovider { 30 namespace fuse { 31 class FuseDaemon final { 32 public: 33 FuseDaemon(JNIEnv* env, jobject mediaProvider); 34 35 ~FuseDaemon() = default; 36 37 /** 38 * Start the FUSE daemon loop that will handle filesystem calls. 39 */ 40 void Start(android::base::unique_fd fd, const std::string& path); 41 42 /** 43 * Checks if the FUSE daemon is started. 44 */ 45 bool IsStarted() const; 46 47 /** 48 * Check if file should be opened with FUSE 49 */ 50 bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path); 51 52 /** 53 * Invalidate FUSE VFS dentry cache entry for path 54 */ 55 void InvalidateFuseDentryCache(const std::string& path); 56 57 /** 58 * Return path of the original media format file for the given file descriptor. 59 */ 60 const std::string GetOriginalMediaFormatFilePath(int fd) const; 61 62 /** 63 * Initialize device id for the FUSE daemon with the FUSE device id of the given path. 64 */ 65 void InitializeDeviceId(const std::string& path); 66 67 private: 68 FuseDaemon(const FuseDaemon&) = delete; 69 void operator=(const FuseDaemon&) = delete; 70 MediaProviderWrapper mp; 71 std::atomic_bool active; 72 struct ::fuse* fuse; 73 }; 74 75 } // namespace fuse 76 } // namespace mediaprovider 77 78 #endif // MEDIAPROVIDER_JNI_FUSEDAEMON_H_ 79