shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 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 | |
Zim | edbe69e | 2019-12-13 18:49:36 +0000 | [diff] [blame] | 20 | #include <memory> |
Zim | 3e45d9b | 2019-08-19 21:14:14 +0100 | [diff] [blame] | 21 | #include <string> |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 22 | |
Martijn Coenen | 083eb69 | 2020-04-24 09:39:58 +0200 | [diff] [blame] | 23 | #include <android-base/unique_fd.h> |
| 24 | |
shafik | c3f6267 | 2019-08-30 11:15:48 +0100 | [diff] [blame] | 25 | #include "MediaProviderWrapper.h" |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 26 | #include "jni.h" |
| 27 | |
Zim | edbe69e | 2019-12-13 18:49:36 +0000 | [diff] [blame] | 28 | struct fuse; |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 29 | namespace mediaprovider { |
| 30 | namespace fuse { |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 31 | class FuseDaemon final { |
shafik | c3f6267 | 2019-08-30 11:15:48 +0100 | [diff] [blame] | 32 | public: |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 33 | FuseDaemon(JNIEnv* env, jobject mediaProvider); |
Zim | 3e45d9b | 2019-08-19 21:14:14 +0100 | [diff] [blame] | 34 | |
Zim | 7e0d314 | 2019-10-17 21:06:12 +0100 | [diff] [blame] | 35 | ~FuseDaemon() = default; |
| 36 | |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Start the FUSE daemon loop that will handle filesystem calls. |
| 39 | */ |
Zim | 763428f | 2021-09-17 11:46:48 +0100 | [diff] [blame] | 40 | void Start(android::base::unique_fd fd, const std::string& path, |
| 41 | const std::vector<std::string>& supported_transcoding_relative_paths); |
shafik | 8b57cd5 | 2019-09-06 10:51:29 +0100 | [diff] [blame] | 42 | |
Zim | edbe69e | 2019-12-13 18:49:36 +0000 | [diff] [blame] | 43 | /** |
Zim | d0435b2 | 2020-03-05 13:52:51 +0000 | [diff] [blame] | 44 | * Checks if the FUSE daemon is started. |
| 45 | */ |
| 46 | bool IsStarted() const; |
| 47 | |
| 48 | /** |
Zim | edbe69e | 2019-12-13 18:49:36 +0000 | [diff] [blame] | 49 | * Check if file should be opened with FUSE |
| 50 | */ |
| 51 | bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path); |
| 52 | |
Zim | a76c349 | 2020-02-19 01:23:26 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Invalidate FUSE VFS dentry cache entry for path |
| 55 | */ |
| 56 | void InvalidateFuseDentryCache(const std::string& path); |
| 57 | |
Biswarup Pal | 93f4ec1 | 2021-02-15 13:39:36 +0000 | [diff] [blame] | 58 | /** |
| 59 | * Return path of the original media format file for the given file descriptor. |
| 60 | */ |
| 61 | const std::string GetOriginalMediaFormatFilePath(int fd) const; |
| 62 | |
| 63 | /** |
| 64 | * Initialize device id for the FUSE daemon with the FUSE device id of the given path. |
| 65 | */ |
| 66 | void InitializeDeviceId(const std::string& path); |
| 67 | |
shafik | 8b57cd5 | 2019-09-06 10:51:29 +0100 | [diff] [blame] | 68 | private: |
Zim | 3e45d9b | 2019-08-19 21:14:14 +0100 | [diff] [blame] | 69 | FuseDaemon(const FuseDaemon&) = delete; |
| 70 | void operator=(const FuseDaemon&) = delete; |
shafik | c3f6267 | 2019-08-30 11:15:48 +0100 | [diff] [blame] | 71 | MediaProviderWrapper mp; |
Zim | edbe69e | 2019-12-13 18:49:36 +0000 | [diff] [blame] | 72 | std::atomic_bool active; |
| 73 | struct ::fuse* fuse; |
shafik | 1e3a267 | 2019-08-16 14:51:55 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace fuse |
| 77 | } // namespace mediaprovider |
| 78 | |
| 79 | #endif // MEDIAPROVIDER_JNI_FUSEDAEMON_H_ |