Better modular build

This commit is contained in:
Matéo Duparc 2022-06-25 19:24:26 +02:00
parent 43a3f72935
commit da7cb57b56
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
6 changed files with 43 additions and 62 deletions

View File

@ -2,33 +2,26 @@ cmake_minimum_required(VERSION 3.10)
project(DroidFS) project(DroidFS)
add_subdirectory(${PROJECT_SOURCE_DIR}/libcryfs/) option(GOCRYPTFS "build libgocryptfs" ON)
option(CRYFS "build libcryfs" ON)
add_library( if (GOCRYPTFS)
gocryptfs add_library(gocryptfs SHARED IMPORTED)
SHARED set_target_properties(
IMPORTED
)
set_target_properties(
gocryptfs gocryptfs
PROPERTIES IMPORTED_LOCATION PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI}/libgocryptfs.so ${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()
add_library( if (CRYFS)
gocryptfs_jni add_subdirectory(${PROJECT_SOURCE_DIR}/libcryfs)
SHARED add_library(cryfs_jni SHARED src/main/native/libcryfs.c)
src/main/native/gocryptfs_jni.c target_link_libraries(cryfs_jni libcryfs-jni)
) endif()
target_link_libraries(
gocryptfs_jni
gocryptfs
)
add_library(cryfs_jni SHARED src/main/native/libcryfs.c)
target_link_libraries(cryfs_jni fspp-fuse)
add_library( add_library(
avformat avformat
@ -72,14 +65,11 @@ add_library(
src/main/native/libmux.c src/main/native/libmux.c
) )
target_include_directories(mux PRIVATE ${PROJECT_SOURCE_DIR}/ffmpeg/build/${ANDROID_ABI})
target_link_libraries( target_link_libraries(
mux mux
avformat avformat
avcodec avcodec
avutil avutil
) )
include_directories(
${PROJECT_SOURCE_DIR}/libgocryptfs/build/${ANDROID_ABI}
${PROJECT_SOURCE_DIR}/ffmpeg/build/${ANDROID_ABI}
)

View File

@ -1,9 +1,16 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
ext { if (hasProperty("disableCryFS")) {
enableCryFS = true ext.disableCryFS = getProperty("disableCryFS")
enableGocryptfs = true } else {
ext.disableCryFS = false
}
if (hasProperty("disableGocryptfs")) {
ext.disableGocryptfs = getProperty("disableGocryptfs")
} else {
ext.disableGocryptfs = false
} }
android { android {
@ -28,12 +35,11 @@ android {
} }
externalNativeBuild.cmake { externalNativeBuild.cmake {
targets "mux" if (project.ext.disableGocryptfs) {
if (project.ext.enableGocryptfs) { arguments "-DGOCRYPTFS=OFF"
targets += "gocryptfs_jni"
} }
if (project.ext.enableCryFS) { if (project.ext.disableCryFS) {
targets += "cryfs_jni" arguments "-DCRYFS=OFF"
} }
} }
} }
@ -49,8 +55,8 @@ android {
applicationVariants.all { variant -> applicationVariants.all { variant ->
variant.resValue "string", "versionName", variant.versionName variant.resValue "string", "versionName", variant.versionName
buildConfigField "boolean", "CRYFS_ENABLED", "${project.ext.enableCryFS}" buildConfigField "boolean", "CRYFS_DISABLED", "${project.ext.disableCryFS}"
buildConfigField "boolean", "GOCRYPTFS_ENABLED", "${project.ext.enableGocryptfs}" buildConfigField "boolean", "GOCRYPTFS_DISABLED", "${project.ext.disableGocryptfs}"
} }
buildFeatures { buildFeatures {

@ -1 +1 @@
Subproject commit fb593c468c62c2f92b0420e80e1f77c001dd3a24 Subproject commit c0af6c0bc2045bb53f65fde02d192d5aca436eae

View File

@ -345,7 +345,7 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
menu.findItem(R.id.change_password).isVisible = menu.findItem(R.id.change_password).isVisible =
onlyOneAndWriteable && onlyOneAndWriteable &&
// Only gocryptfs volumes support password change // Only gocryptfs volumes support password change
BuildConfig.GOCRYPTFS_ENABLED && !BuildConfig.GOCRYPTFS_DISABLED &&
volumeAdapter.volumes[volumeAdapter.selectedItems.first()].type == EncryptedVolume.GOCRYPTFS_VOLUME_TYPE volumeAdapter.volumes[volumeAdapter.selectedItems.first()].type == EncryptedVolume.GOCRYPTFS_VOLUME_TYPE
menu.findItem(R.id.remove_default_open).isVisible = menu.findItem(R.id.remove_default_open).isVisible =
onlyOneSelected && onlyOneSelected &&
@ -461,10 +461,10 @@ class MainActivity : BaseActivity(), VolumeAdapter.Listener {
@SuppressLint("NewApi") // fingerprintProtector is non-null only when SDK_INT >= 23 @SuppressLint("NewApi") // fingerprintProtector is non-null only when SDK_INT >= 23
private fun openVolume(volume: SavedVolume, position: Int) { 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() Toast.makeText(this, R.string.gocryptfs_disabled, Toast.LENGTH_SHORT).show()
return 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() Toast.makeText(this, R.string.cryfs_disabled, Toast.LENGTH_SHORT).show()
return return
} }

View File

@ -85,10 +85,10 @@ class CreateVolumeFragment: Fragment() {
if (!usfFingerprint || fingerprintProtector == null) { if (!usfFingerprint || fingerprintProtector == null) {
binding.checkboxSavePassword.visibility = View.GONE binding.checkboxSavePassword.visibility = View.GONE
} }
if (BuildConfig.GOCRYPTFS_ENABLED) { if (!BuildConfig.GOCRYPTFS_DISABLED) {
volumeTypes.add(resources.getString(R.string.gocryptfs)) volumeTypes.add(resources.getString(R.string.gocryptfs))
} }
if (BuildConfig.CRYFS_ENABLED) { if (!BuildConfig.CRYFS_DISABLED) {
volumeTypes.add(resources.getString(R.string.cryfs)) volumeTypes.add(resources.getString(R.string.cryfs))
} }
binding.spinnerVolumeType.adapter = ArrayAdapter( binding.spinnerVolumeType.adapter = ArrayAdapter(

View File

@ -1,21 +1,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <jni.h> #include <jni.h>
#include <libcryfs-jni.h>
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);
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_sushi_hardcore_droidfs_filesystems_CryfsVolume_00024Companion_nativeInit(JNIEnv *env, jobject thiz, Java_sushi_hardcore_droidfs_filesystems_CryfsVolume_00024Companion_nativeInit(JNIEnv *env, jobject thiz,