From e9982bf1b53682416b3965ca5dd91012b011d258 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 8 Jun 2024 16:55:15 +0100 Subject: [PATCH] Filter Android drivers according to SDL_***_DISABLED macros to help reduce APK size (#9986) --- Android.mk | 2 ++ .../build_config/SDL_build_config_android.h | 12 ++++++-- src/core/android/SDL_android.c | 30 +++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Android.mk b/Android.mk index d6c03a6112..01f7460898 100644 --- a/Android.mk +++ b/Android.mk @@ -37,6 +37,7 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/file/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/hidapi/*.c) \ $(wildcard $(LOCAL_PATH)/src/hidapi/android/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ @@ -58,6 +59,7 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/filesystem/posix/*.c) \ $(wildcard $(LOCAL_PATH)/src/sensor/*.c) \ $(wildcard $(LOCAL_PATH)/src/sensor/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/sensor/dummy/*.c) \ $(wildcard $(LOCAL_PATH)/src/render/*.c) \ $(wildcard $(LOCAL_PATH)/src/render/*/*.c) \ $(wildcard $(LOCAL_PATH)/src/stdlib/*.c) \ diff --git a/include/build_config/SDL_build_config_android.h b/include/build_config/SDL_build_config_android.h index 61b2035dcc..314e9416c0 100644 --- a/include/build_config/SDL_build_config_android.h +++ b/include/build_config/SDL_build_config_android.h @@ -140,19 +140,26 @@ #define HAVE_CLOCK_GETTIME 1 /* Enable various audio drivers */ +#ifndef SDL_AUDIO_DISABLED #define SDL_AUDIO_DRIVER_ANDROID 1 #define SDL_AUDIO_DRIVER_OPENSLES 1 #define SDL_AUDIO_DRIVER_AAUDIO 1 -#define SDL_AUDIO_DRIVER_DUMMY 1 +#endif /* SDL_AUDIO_DISABLED */ /* Enable various input drivers */ +#ifndef SDL_JOYSTICK_DISABLED #define SDL_JOYSTICK_ANDROID 1 #define SDL_JOYSTICK_HIDAPI 1 #define SDL_JOYSTICK_VIRTUAL 1 +#endif /* SDL_JOYSTICK_DISABLED */ +#ifndef SDL_HAPTIC_DISABLED #define SDL_HAPTIC_ANDROID 1 +#endif /* SDL_HAPTIC_DISABLED */ /* Enable sensor driver */ +#ifndef SDL_SENSOR_DISABLED #define SDL_SENSOR_ANDROID 1 +#endif /* SDL_SENSOR_DISABLED */ /* Enable various shared object loading systems */ #define SDL_LOADSO_DLOPEN 1 @@ -192,8 +199,9 @@ #define SDL_FSOPS_POSIX 1 /* Enable the camera driver */ +#ifndef SDL_CAMERA_DISABLED #define SDL_CAMERA_DRIVER_ANDROID 1 -#define SDL_CAMERA_DRIVER_DUMMY 1 +#endif /* SDL_CAMERA_DISABLED */ /* Enable nl_langinfo and high-res file times on version 26 and higher. */ #if __ANDROID_API__ >= 26 diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 70d5096545..2cffd3b5d5 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -1041,7 +1041,11 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( JNIEnv *env, jclass jcls, jint device_id, jint keycode) { +#ifdef SDL_JOYSTICK_ANDROID return Android_OnPadDown(device_id, keycode); +#else + return -1; +#endif /* SDL_JOYSTICK_ANDROID */ } /* Padup */ @@ -1049,7 +1053,11 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( JNIEnv *env, jclass jcls, jint device_id, jint keycode) { +#ifdef SDL_JOYSTICK_ANDROID return Android_OnPadUp(device_id, keycode); +#else + return -1; +#endif /* SDL_JOYSTICK_ANDROID */ } /* Joy */ @@ -1057,7 +1065,9 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy)( JNIEnv *env, jclass jcls, jint device_id, jint axis, jfloat value) { +#ifdef SDL_JOYSTICK_ANDROID Android_OnJoy(device_id, axis, value); +#endif /* SDL_JOYSTICK_ANDROID */ } /* POV Hat */ @@ -1065,7 +1075,9 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)( JNIEnv *env, jclass jcls, jint device_id, jint hat_id, jint x, jint y) { +#ifdef SDL_JOYSTICK_ANDROID Android_OnHat(device_id, hat_id, x, y); +#endif /* SDL_JOYSTICK_ANDROID */ } JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( @@ -1075,6 +1087,7 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( jint button_mask, jint naxes, jint axis_mask, jint nhats, jboolean can_rumble) { int retval; +#ifdef SDL_JOYSTICK_ANDROID const char *name = (*env)->GetStringUTFChars(env, device_name, NULL); const char *desc = (*env)->GetStringUTFChars(env, device_desc, NULL); @@ -1082,7 +1095,9 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( (*env)->ReleaseStringUTFChars(env, device_name, name); (*env)->ReleaseStringUTFChars(env, device_desc, desc); - +#else + retval = -1; +#endif /* SDL_JOYSTICK_ANDROID */ return retval; } @@ -1090,26 +1105,37 @@ JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)( JNIEnv *env, jclass jcls, jint device_id) { +#ifdef SDL_JOYSTICK_ANDROID return Android_RemoveJoystick(device_id); +#else + return -1; +#endif /* SDL_JOYSTICK_ANDROID */ } JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)( JNIEnv *env, jclass jcls, jint device_id, jstring device_name) { int retval; +#ifdef SDL_HAPTIC_ANDROID const char *name = (*env)->GetStringUTFChars(env, device_name, NULL); retval = Android_AddHaptic(device_id, name); (*env)->ReleaseStringUTFChars(env, device_name, name); - +#else + retval = -1; +#endif /* SDL_HAPTIC_ANDROID */ return retval; } JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( JNIEnv *env, jclass jcls, jint device_id) { +#ifdef SDL_HAPTIC_ANDROID return Android_RemoveHaptic(device_id); +#else + return -1; +#endif } /* Called from surfaceCreated() */