blob: 31648300bd08e68c26f5a8b51feb79fdf2731ed4 [file] [log] [blame]
shafik1e3a2672019-08-16 14:51:55 +01001/*
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
Zimedbe69e2019-12-13 18:49:36 +000020#include <memory>
Zim3e45d9b2019-08-19 21:14:14 +010021#include <string>
shafik1e3a2672019-08-16 14:51:55 +010022
Martijn Coenen083eb692020-04-24 09:39:58 +020023#include <android-base/unique_fd.h>
24
shafikc3f62672019-08-30 11:15:48 +010025#include "MediaProviderWrapper.h"
shafik1e3a2672019-08-16 14:51:55 +010026#include "jni.h"
27
Zimedbe69e2019-12-13 18:49:36 +000028struct fuse;
shafik1e3a2672019-08-16 14:51:55 +010029namespace mediaprovider {
30namespace fuse {
shafik1e3a2672019-08-16 14:51:55 +010031class FuseDaemon final {
shafikc3f62672019-08-30 11:15:48 +010032 public:
shafik1e3a2672019-08-16 14:51:55 +010033 FuseDaemon(JNIEnv* env, jobject mediaProvider);
Zim3e45d9b2019-08-19 21:14:14 +010034
Zim7e0d3142019-10-17 21:06:12 +010035 ~FuseDaemon() = default;
36
shafik1e3a2672019-08-16 14:51:55 +010037 /**
38 * Start the FUSE daemon loop that will handle filesystem calls.
39 */
Zim763428f2021-09-17 11:46:48 +010040 void Start(android::base::unique_fd fd, const std::string& path,
41 const std::vector<std::string>& supported_transcoding_relative_paths);
shafik8b57cd52019-09-06 10:51:29 +010042
Zimedbe69e2019-12-13 18:49:36 +000043 /**
Zimd0435b22020-03-05 13:52:51 +000044 * Checks if the FUSE daemon is started.
45 */
46 bool IsStarted() const;
47
48 /**
Zimedbe69e2019-12-13 18:49:36 +000049 * Check if file should be opened with FUSE
50 */
51 bool ShouldOpenWithFuse(int fd, bool for_read, const std::string& path);
52
Zima76c3492020-02-19 01:23:26 +000053 /**
54 * Invalidate FUSE VFS dentry cache entry for path
55 */
56 void InvalidateFuseDentryCache(const std::string& path);
57
Biswarup Pal93f4ec12021-02-15 13:39:36 +000058 /**
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
shafik8b57cd52019-09-06 10:51:29 +010068 private:
Zim3e45d9b2019-08-19 21:14:14 +010069 FuseDaemon(const FuseDaemon&) = delete;
70 void operator=(const FuseDaemon&) = delete;
shafikc3f62672019-08-30 11:15:48 +010071 MediaProviderWrapper mp;
Zimedbe69e2019-12-13 18:49:36 +000072 std::atomic_bool active;
73 struct ::fuse* fuse;
shafik1e3a2672019-08-16 14:51:55 +010074};
75
76} // namespace fuse
77} // namespace mediaprovider
78
79#endif // MEDIAPROVIDER_JNI_FUSEDAEMON_H_