blob: 175d49c16f4a469583859901a4f59063178336ce [file] [log] [blame]
Zim3e45d9b2019-08-19 21:14:14 +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// Need to use LOGE_EX.
18#define LOG_TAG "FuseDaemon"
19
20#include "FuseDaemon.h"
21
22#include <string>
23
24#include <nativehelper/JNIHelp.h>
25#include <nativehelper/scoped_utf_chars.h>
26#include <cutils/log.h>
27
28namespace mediaprovider {
29namespace {
30
31constexpr const char* CLASS_NAME = "com/android/providers/media/fuse/FuseDaemon";
32static jclass gFuseDaemonClass;
33
34jlong com_android_providers_media_FuseDaemon_new(JNIEnv* env, jobject self,
35 jobject mediaProvider) {
36 ALOGD("Creating the FUSE daemon...\n");
37 return reinterpret_cast<jlong>(new fuse::FuseDaemon(env, mediaProvider));
38}
39
40void com_android_providers_media_FuseDaemon_start(
41 JNIEnv* env, jobject self, jlong java_daemon, jint fd, jstring java_upper_path,
42 jstring java_lower_path) {
43 ALOGD("Starting the FUSE daemon...");
44 fuse::FuseDaemon* const daemon = reinterpret_cast<fuse::FuseDaemon*>(java_daemon);
45
46 ScopedUtfChars utf_chars_upper_path(env, java_upper_path);
47 if (!utf_chars_upper_path.c_str()) {
48 return;
49 }
50 const std::string& string_upper_path = std::string(utf_chars_upper_path.c_str());
51
52 ScopedUtfChars utf_chars_lower_path(env, java_lower_path);
53 if (!utf_chars_lower_path.c_str()) {
54 return;
55 }
56 const std::string& string_lower_path = std::string(utf_chars_lower_path.c_str());
57
58 daemon->Start(fd, string_upper_path, string_lower_path);
59}
60
61void com_android_providers_media_FuseDaemon_stop(
62 JNIEnv* env, jobject self, jlong java_daemon) {
63 ALOGD("Stopping the FUSE daemon...");
64 fuse::FuseDaemon* const daemon = reinterpret_cast<fuse::FuseDaemon*>(java_daemon);
65 daemon->Stop();
66}
67
68void com_android_providers_media_FuseDaemon_delete(
69 JNIEnv* env, jobject self, jlong java_daemon) {
70 ALOGD("Destroying the FUSE daemon...");
71 fuse::FuseDaemon* const daemon = reinterpret_cast<fuse::FuseDaemon*>(java_daemon);
72 delete daemon;
73}
74
75const JNINativeMethod methods[] = {
76 {
77 "native_new",
78 "(Lcom/android/providers/media/MediaProvider;)J",
79 reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_new)
80 },
81 {
82 "native_start",
83 "(JILjava/lang/String;Ljava/lang/String;)V",
84 reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_start)
85 },
86 {
87 "native_stop",
88 "(J)V",
89 reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_stop)
90 },
91 {
92 "native_delete",
93 "(J)V",
94 reinterpret_cast<void*>(com_android_providers_media_FuseDaemon_delete)
95 }
96};
97} // namespace
98
99void register_android_providers_media_FuseDaemon(JNIEnv* env) {
100 gFuseDaemonClass = static_cast<jclass>(env->NewGlobalRef(env->FindClass(CLASS_NAME)));
101 jniRegisterNativeMethods(env, CLASS_NAME, methods, NELEM(methods));
102}
103} // namespace mediaprovider