(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+).
This commit is contained in:
Googer 2015-02-24 12:20:21 -05:00
parent 719ecf014b
commit 03b4ace443
2 changed files with 64 additions and 14 deletions

View File

@ -20,7 +20,6 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/system_properties.h>
#include "platform_android.h" #include "platform_android.h"
@ -429,16 +428,48 @@ static bool android_run_events(void *data)
return true; 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) 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)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]; 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; *major = 0;
*minor = 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) static bool device_is_xperia_play(const char *name)
{ {
if ( if (
@ -669,7 +713,7 @@ static void frontend_android_get_environment_settings(int *argc,
} }
frontend_android_get_name(device_model, sizeof(device_model)); 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; g_defaults.settings.video_threaded_enable = true;

View File

@ -90,7 +90,7 @@ typedef struct android_input
const rarch_joypad_driver_t *joypad; const rarch_joypad_driver_t *joypad;
} android_input_t; } 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, bool (*engine_lookup_name)(char *buf,
int *vendorId, int *productId, size_t size, int id); 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); 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) int *vendorId, int *productId, size_t size, int id)
{ {
RARCH_LOG("Using old lookup");
jclass class; jclass class;
jmethodID method, getName; jmethodID method, getName;
jobject device, name; jobject device, name;
@ -210,9 +212,11 @@ error:
return false; 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) int *vendorId, int *productId, size_t size, int id)
{ {
RARCH_LOG("Using new lookup");
jclass class; jclass class;
jmethodID method, getName, getVendorId, getProductId; jmethodID method, getName, getVendorId, getProductId;
jobject device, name; jobject device, name;
@ -297,7 +301,7 @@ error:
static void *android_input_init(void) 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)); android_input_t *android = (android_input_t*)calloc(1, sizeof(*android));
if (!android) if (!android)
@ -306,12 +310,14 @@ static void *android_input_init(void)
android->pads_connected = 0; android->pads_connected = 0;
android->joypad = input_joypad_init_driver(g_settings.input.joypad_driver); 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; RARCH_LOG("sdk version: %d\n", sdk);
if (major == 2 && minor == 3) if (sdk >= 19)
engine_lookup_name = android_input_lookup_name_gingerbread; engine_lookup_name = android_input_lookup_name;
else
engine_lookup_name = android_input_lookup_name_prekitkat;
return android; return android;
} }