From 719ecf014b960ccefa56e993484099d694cc116d Mon Sep 17 00:00:00 2001 From: Googer Date: Tue, 24 Feb 2015 12:17:06 -0500 Subject: [PATCH 1/3] (Android) Fix compilation. --- gfx/drivers_context/androidegl_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/drivers_context/androidegl_ctx.c b/gfx/drivers_context/androidegl_ctx.c index dc923bc879..8b406ddd85 100644 --- a/gfx/drivers_context/androidegl_ctx.c +++ b/gfx/drivers_context/androidegl_ctx.c @@ -22,7 +22,7 @@ #include #include "../../frontend/drivers/platform_android.h" -#include "../image/image.h" +#include #include From 03b4ace443802fd301ef0b5e03540ace5dea4f0a Mon Sep 17 00:00:00 2001 From: Googer Date: Tue, 24 Feb 2015 12:20:21 -0500 Subject: [PATCH 2/3] (Android) Fix pad input detection for pre-KitKat. Also update getting system properties to use getprop command instead of __system_property_get. Use sdk level to determine which gamepad detection method to use (only use vendorId and productId if at least KitKat - i.e., SDK version 19+). --- frontend/drivers/platform_android.c | 54 ++++++++++++++++++++++++++--- input/drivers/android_input.c | 24 ++++++++----- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/frontend/drivers/platform_android.c b/frontend/drivers/platform_android.c index 61a121547b..8e2bea351f 100644 --- a/frontend/drivers/platform_android.c +++ b/frontend/drivers/platform_android.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "platform_android.h" @@ -429,16 +428,48 @@ static bool android_run_events(void *data) return true; } +static int system_property_get(const char *name, char *value) +{ + char cmd[1024]; + + sprintf(cmd, "getprop %s", name); + FILE *pipe = popen(cmd, "r"); + if (!pipe) + { + RARCH_ERR("Could not create pipe.\n"); + return 0; + } + + int length = 0; + char buffer[128]; + char *curpos = value; + + while (!feof(pipe)) + { + if (fgets(buffer, 128, pipe) != NULL) + { + memcpy(curpos, buffer, strlen(buffer)); + curpos += strlen(buffer); + length += strlen(buffer); + } + } + *curpos = '\0'; + + pclose(pipe); + + return length; +} + static void frontend_android_get_name(char *name, size_t sizeof_name) { - int len = __system_property_get("ro.product.model", name); + int len = system_property_get("ro.product.model", name); (void)len; } -void frontend_android_get_version(int32_t *major, int32_t *minor, int32_t *bugfix) +static void frontend_android_get_version(int32_t *major, int32_t *minor, int32_t *bugfix) { char os_version_str[PROP_VALUE_MAX]; - __system_property_get("ro.build.version.release", os_version_str); + system_property_get("ro.build.version.release", os_version_str); *major = 0; *minor = 0; @@ -461,6 +492,19 @@ void frontend_android_get_version(int32_t *major, int32_t *minor, int32_t *bugfi } } +static void frontend_android_get_version_sdk(int32_t *sdk) +{ + char os_version_str[PROP_VALUE_MAX]; + system_property_get("ro.build.version.sdk", os_version_str); + + *sdk = 0; + if (os_version_str[0]) + { + int num_read = sscanf(os_version_str, "%d", sdk); + (void) num_read; + } +} + static bool device_is_xperia_play(const char *name) { if ( @@ -669,7 +713,7 @@ static void frontend_android_get_environment_settings(int *argc, } frontend_android_get_name(device_model, sizeof(device_model)); - __system_property_get("ro.product.id", device_id); + system_property_get("ro.product.id", device_id); g_defaults.settings.video_threaded_enable = true; diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index fbc9c608c9..6040a77fed 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -90,7 +90,7 @@ typedef struct android_input const rarch_joypad_driver_t *joypad; } android_input_t; -void frontend_android_get_version(int32_t *major, int32_t *minor, int32_t *bugfix); +static void frontend_android_get_version_sdk(int32_t *sdk); bool (*engine_lookup_name)(char *buf, int *vendorId, int *productId, size_t size, int id); @@ -152,9 +152,11 @@ static void engine_handle_dpad_getaxisvalue(android_input_t *android, android->analog_state[port][9] = (int16_t)(gas * 32767.0f); } -static bool android_input_lookup_name_gingerbread(char *buf, +static bool android_input_lookup_name_prekitkat(char *buf, int *vendorId, int *productId, size_t size, int id) { + RARCH_LOG("Using old lookup"); + jclass class; jmethodID method, getName; jobject device, name; @@ -210,9 +212,11 @@ error: return false; } -static bool android_input_lookup_name_post_gingerbread(char *buf, +static bool android_input_lookup_name(char *buf, int *vendorId, int *productId, size_t size, int id) { + RARCH_LOG("Using new lookup"); + jclass class; jmethodID method, getName, getVendorId, getProductId; jobject device, name; @@ -297,7 +301,7 @@ error: static void *android_input_init(void) { - int32_t major, minor, bugfix; + int32_t sdk; android_input_t *android = (android_input_t*)calloc(1, sizeof(*android)); if (!android) @@ -306,12 +310,14 @@ static void *android_input_init(void) android->pads_connected = 0; android->joypad = input_joypad_init_driver(g_settings.input.joypad_driver); - frontend_android_get_version(&major, &minor, &bugfix); + frontend_android_get_version_sdk(&sdk); - engine_lookup_name = android_input_lookup_name_post_gingerbread; - - if (major == 2 && minor == 3) - engine_lookup_name = android_input_lookup_name_gingerbread; + RARCH_LOG("sdk version: %d\n", sdk); + + if (sdk >= 19) + engine_lookup_name = android_input_lookup_name; + else + engine_lookup_name = android_input_lookup_name_prekitkat; return android; } From fe176fc01bcf89305a65572a174102b0d270919b Mon Sep 17 00:00:00 2001 From: Googer Date: Tue, 24 Feb 2015 12:41:23 -0500 Subject: [PATCH 3/3] Fixed silly repeated calls to strlen() --- frontend/drivers/platform_android.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/drivers/platform_android.c b/frontend/drivers/platform_android.c index 8e2bea351f..f2bf63ee77 100644 --- a/frontend/drivers/platform_android.c +++ b/frontend/drivers/platform_android.c @@ -448,9 +448,10 @@ static int system_property_get(const char *name, char *value) { if (fgets(buffer, 128, pipe) != NULL) { - memcpy(curpos, buffer, strlen(buffer)); - curpos += strlen(buffer); - length += strlen(buffer); + int curlen = strlen(buffer); + memcpy(curpos, buffer, curlen); + curpos += curlen; + length += curlen; } } *curpos = '\0'; @@ -501,7 +502,7 @@ static void frontend_android_get_version_sdk(int32_t *sdk) if (os_version_str[0]) { int num_read = sscanf(os_version_str, "%d", sdk); - (void) num_read; + (void) num_read; } }