From da7cb57b56ee1063b766410744a1be0d42b4274a Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sat, 25 Jun 2022 19:24:26 +0200 Subject: [PATCH] Better modular build --- app/CMakeLists.txt | 50 ++++++++----------- app/build.gradle | 26 ++++++---- app/libcryfs | 2 +- .../sushi/hardcore/droidfs/MainActivity.kt | 6 +-- .../add_volume/CreateVolumeFragment.kt | 4 +- app/src/main/native/libcryfs.c | 17 +------ 6 files changed, 43 insertions(+), 62 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 20148fd..2d522e6 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,33 +2,26 @@ cmake_minimum_required(VERSION 3.10) project(DroidFS) -add_subdirectory(${PROJECT_SOURCE_DIR}/libcryfs/) +option(GOCRYPTFS "build libgocryptfs" ON) +option(CRYFS "build libcryfs" ON) -add_library( - gocryptfs - SHARED - IMPORTED -) +if (GOCRYPTFS) + add_library(gocryptfs SHARED IMPORTED) + set_target_properties( + gocryptfs + PROPERTIES IMPORTED_LOCATION + ${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI}/libgocryptfs.so + ) + add_library(gocryptfs_jni SHARED src/main/native/gocryptfs_jni.c) + target_include_directories(gocryptfs_jni PRIVATE ${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI}) + target_link_libraries(gocryptfs_jni gocryptfs) +endif() -set_target_properties( - gocryptfs - PROPERTIES IMPORTED_LOCATION - ${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI}/libgocryptfs.so -) - -add_library( - gocryptfs_jni - SHARED - src/main/native/gocryptfs_jni.c -) - -target_link_libraries( - gocryptfs_jni - gocryptfs -) - -add_library(cryfs_jni SHARED src/main/native/libcryfs.c) -target_link_libraries(cryfs_jni fspp-fuse) +if (CRYFS) + add_subdirectory(${PROJECT_SOURCE_DIR}/libcryfs) + add_library(cryfs_jni SHARED src/main/native/libcryfs.c) + target_link_libraries(cryfs_jni libcryfs-jni) +endif() add_library( avformat @@ -72,14 +65,11 @@ add_library( src/main/native/libmux.c ) +target_include_directories(mux PRIVATE ${PROJECT_SOURCE_DIR}/ffmpeg/build/${ANDROID_ABI}) + target_link_libraries( mux avformat avcodec avutil -) - -include_directories( - ${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI} - ${PROJECT_SOURCE_DIR}/ffmpeg/build/${ANDROID_ABI} ) \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ba3614d..624806d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,9 +1,16 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -ext { - enableCryFS = true - enableGocryptfs = true +if (hasProperty("disableCryFS")) { + ext.disableCryFS = getProperty("disableCryFS") +} else { + ext.disableCryFS = false +} + +if (hasProperty("disableGocryptfs")) { + ext.disableGocryptfs = getProperty("disableGocryptfs") +} else { + ext.disableGocryptfs = false } android { @@ -28,12 +35,11 @@ android { } externalNativeBuild.cmake { - targets "mux" - if (project.ext.enableGocryptfs) { - targets += "gocryptfs_jni" + if (project.ext.disableGocryptfs) { + arguments "-DGOCRYPTFS=OFF" } - if (project.ext.enableCryFS) { - targets += "cryfs_jni" + if (project.ext.disableCryFS) { + arguments "-DCRYFS=OFF" } } } @@ -49,8 +55,8 @@ android { applicationVariants.all { variant -> variant.resValue "string", "versionName", variant.versionName - buildConfigField "boolean", "CRYFS_ENABLED", "${project.ext.enableCryFS}" - buildConfigField "boolean", "GOCRYPTFS_ENABLED", "${project.ext.enableGocryptfs}" + buildConfigField "boolean", "CRYFS_DISABLED", "${project.ext.disableCryFS}" + buildConfigField "boolean", "GOCRYPTFS_DISABLED", "${project.ext.disableGocryptfs}" } buildFeatures { diff --git a/app/libcryfs b/app/libcryfs index fb593c4..c0af6c0 160000 --- a/app/libcryfs +++ b/app/libcryfs @@ -1 +1 @@ -Subproject commit fb593c468c62c2f92b0420e80e1f77c001dd3a24 +Subproject commit c0af6c0bc2045bb53f65fde02d192d5aca436eae diff --git a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt index 31f602f..4d679f0 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/MainActivity.kt @@ -345,7 +345,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener { menu.findItem(R.id.change_password).isVisible = onlyOneAndWriteable && // Only gocryptfs volumes support password change - BuildConfig.GOCRYPTFS_ENABLED && + !BuildConfig.GOCRYPTFS_DISABLED && volumeAdapter.volumes[volumeAdapter.selectedItems.first()].type == EncryptedVolume.GOCRYPTFS_VOLUME_TYPE menu.findItem(R.id.remove_default_open).isVisible = onlyOneSelected && @@ -461,10 +461,10 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener { @SuppressLint("NewApi") // fingerprintProtector is non-null only when SDK_INT >= 23 private fun openVolume(volume: SavedVolume, position: Int) { - if (volume.type == EncryptedVolume.GOCRYPTFS_VOLUME_TYPE && !BuildConfig.GOCRYPTFS_ENABLED) { + if (volume.type == EncryptedVolume.GOCRYPTFS_VOLUME_TYPE && BuildConfig.GOCRYPTFS_DISABLED) { Toast.makeText(this, R.string.gocryptfs_disabled, Toast.LENGTH_SHORT).show() return - } else if (volume.type == EncryptedVolume.CRYFS_VOLUME_TYPE && !BuildConfig.CRYFS_ENABLED) { + } else if (volume.type == EncryptedVolume.CRYFS_VOLUME_TYPE && BuildConfig.CRYFS_DISABLED) { Toast.makeText(this, R.string.cryfs_disabled, Toast.LENGTH_SHORT).show() return } diff --git a/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt b/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt index 3e252bd..279581e 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/add_volume/CreateVolumeFragment.kt @@ -85,10 +85,10 @@ class CreateVolumeFragment: Fragment() { if (!usfFingerprint || fingerprintProtector == null) { binding.checkboxSavePassword.visibility = View.GONE } - if (BuildConfig.GOCRYPTFS_ENABLED) { + if (!BuildConfig.GOCRYPTFS_DISABLED) { volumeTypes.add(resources.getString(R.string.gocryptfs)) } - if (BuildConfig.CRYFS_ENABLED) { + if (!BuildConfig.CRYFS_DISABLED) { volumeTypes.add(resources.getString(R.string.cryfs)) } binding.spinnerVolumeType.adapter = ArrayAdapter( diff --git a/app/src/main/native/libcryfs.c b/app/src/main/native/libcryfs.c index f36c351..134f660 100644 --- a/app/src/main/native/libcryfs.c +++ b/app/src/main/native/libcryfs.c @@ -1,21 +1,6 @@ #include #include - -jlong cryfs_init(JNIEnv* env, jstring jbaseDir, jstring jlocalSateDir, jbyteArray jpassword, jboolean createBaseDir, jstring jcipher); -jlong cryfs_create(JNIEnv* env, jlong fusePtr, jstring jpath, mode_t mode); -jlong cryfs_open(JNIEnv* env, jlong fusePtr, jstring jpath, jint flags); -jint cryfs_read(JNIEnv* env, jlong fusePtr, jlong fileHandle, jbyteArray jbuffer, jlong offset); -jint cryfs_write(JNIEnv* env, jlong fusePtr, jlong fileHandle, jlong offset, jbyteArray jbuffer, jint size); -jint cryfs_truncate(JNIEnv* env, jlong fusePtr, jstring jpath, jlong size); -jint cryfs_unlink(JNIEnv* env, jlong fusePtr, jstring jpath); -jint cryfs_release(jlong fusePtr, jlong fileHandle); -jlong cryfs_readdir(JNIEnv* env, jlong fusePtr, jstring jpath ,void* data, int(void*, const char*, const struct stat*)); -jint cryfs_mkdir(JNIEnv* env, jlong fusePtr, jstring jpath, mode_t mode); -jint cryfs_rmdir(JNIEnv* env, jlong fusePtr, jstring jpath); -jint cryfs_getattr(JNIEnv* env, jlong fusePtr, jstring jpath, struct stat* stat); -jint cryfs_rename(JNIEnv* env, jlong fusePtr, jstring jsrcPath, jstring jdstPath); -void cryfs_destroy(jlong fusePtr); -jboolean cryfs_is_closed(jlong fusePtr); +#include JNIEXPORT jlong JNICALL Java_sushi_hardcore_droidfs_filesystems_CryfsVolume_00024Companion_nativeInit(JNIEnv *env, jobject thiz,