Merge pull request #1448 from Googer/master

Fix unimplemented use of getVendorID and getProductID in Android <= 4.3
This commit is contained in:
Twinaphex 2015-02-25 05:04:16 +11:00
commit 8d7be9d6b8
3 changed files with 66 additions and 15 deletions

View File

@ -20,7 +20,6 @@
#include <unistd.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/system_properties.h>
#include "platform_android.h"
@ -429,16 +428,49 @@ 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)
{
int curlen = strlen(buffer);
memcpy(curpos, buffer, curlen);
curpos += curlen;
length += curlen;
}
}
*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 +493,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 +714,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;

View File

@ -22,7 +22,7 @@
#include <EGL/egl.h>
#include "../../frontend/drivers/platform_android.h"
#include "../image/image.h"
#include <formats/image.h>
#include <stdint.h>

View File

@ -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;
RARCH_LOG("sdk version: %d\n", sdk);
if (major == 2 && minor == 3)
engine_lookup_name = android_input_lookup_name_gingerbread;
if (sdk >= 19)
engine_lookup_name = android_input_lookup_name;
else
engine_lookup_name = android_input_lookup_name_prekitkat;
return android;
}