Cleanups in platform_unix.c

This commit is contained in:
LibretroAdmin 2022-10-29 18:37:12 +02:00
parent 3a6a34b2dd
commit 91d7f5970b

View File

@ -94,6 +94,8 @@
#endif
#ifdef ANDROID
static void frontend_unix_set_sustained_performance_mode(bool on);
enum
{
/* Internal SDCARD writable */
@ -104,40 +106,37 @@ enum
INTERNAL_STORAGE_NOT_WRITABLE
};
unsigned storage_permissions = 0;
static void frontend_unix_set_sustained_performance_mode(bool on);
struct android_app *g_android = NULL;
enum platform_android_flags
{
PLAT_ANDROID_FLAG_GAME_CONSOLE_DEVICE = (1 << 0),
PLAT_ANDROID_FLAG_ANDROID_TV_DEVICE = (1 << 1)
};
static pthread_key_t thread_key;
static char screenshot_dir[PATH_MAX_LENGTH];
static char downloads_dir[PATH_MAX_LENGTH];
static char apk_dir[PATH_MAX_LENGTH];
static char app_dir[PATH_MAX_LENGTH];
static bool is_android_tv_device = false;
unsigned storage_permissions = 0;
struct android_app *g_android = NULL;
static uint8_t g_platform_android_flags = 0;
#else
static const char *proc_apm_path = "/proc/apm";
static const char *proc_acpi_battery_path = "/proc/acpi/battery";
static const char *proc_acpi_sysfs_ac_adapter_path = "/sys/class/power_supply/ACAD";
static const char *proc_acpi_sysfs_battery_path = "/sys/class/power_supply";
static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
static char unix_cpu_model_name[64] = {0};
#define PROC_APM_PATH "/proc/apm"
#define PROC_ACPI_BATTERY_PATH "/proc/acpi/battery"
#define PROC_ACPI_SYSFS_AC_ADAPTER_PATH "/sys/class/power_supply/ACAD"
#define PROC_ACPI_SYSFS_BATTERY_PATH "/sys/class/power_supply"
#define PROC_ACPI_AC_ADAPTER_PATH "/proc/acpi/ac_adapter"
static char unix_cpu_model_name[64] = {0};
#endif
/* /proc/meminfo parameters */
#define PROC_MEMINFO_PATH "/proc/meminfo"
#define PROC_MEMINFO_MEM_TOTAL_TAG "MemTotal:"
#define PROC_MEMINFO_MEM_AVAILABLE_TAG "MemAvailable:"
#define PROC_MEMINFO_MEM_FREE_TAG "MemFree:"
#define PROC_MEMINFO_BUFFERS_TAG "Buffers:"
#define PROC_MEMINFO_CACHED_TAG "Cached:"
#define PROC_MEMINFO_SHMEM_TAG "Shmem:"
#define PROC_MEMINFO_PATH "/proc/meminfo"
#define PROC_MEMINFO_MEM_TOTAL_TAG "MemTotal:"
#define PROC_MEMINFO_MEM_AVAILABLE_TAG "MemAvailable:"
#define PROC_MEMINFO_MEM_FREE_TAG "MemFree:"
#define PROC_MEMINFO_BUFFERS_TAG "Buffers:"
#define PROC_MEMINFO_CACHED_TAG "Cached:"
#define PROC_MEMINFO_SHMEM_TAG "Shmem:"
#if (defined(__linux__) || defined(__unix__)) && !defined(ANDROID)
static int speak_pid = 0;
static int speak_pid = 0;
#endif
static volatile sig_atomic_t unix_sighandler_quit;
@ -595,6 +594,7 @@ static bool device_is_xperia_play(const char *name)
return false;
}
/* TODO/FIXME - unfinished */
static bool device_is_game_console(const char *name)
{
if (
@ -612,11 +612,6 @@ static bool device_is_game_console(const char *name)
return false;
}
static bool device_is_android_tv()
{
return is_android_tv_device;
}
bool test_permissions(const char *path)
{
char buf[PATH_MAX_LENGTH];
@ -691,7 +686,6 @@ static void check_proc_acpi_battery(const char * node, bool * have_battery,
{
char basenode[512];
char path[PATH_MAX_LENGTH];
const char *base = proc_acpi_battery_path;
int64_t length = 0;
char *ptr = NULL;
char *buf = NULL;
@ -705,7 +699,8 @@ static void check_proc_acpi_battery(const char * node, bool * have_battery,
int secs = -1;
int pct = -1;
fill_pathname_join_special(basenode, base, node, sizeof(basenode));
fill_pathname_join_special(basenode, PROC_ACPI_BATTERY_PATH,
node, sizeof(basenode));
fill_pathname_join_special(path, basenode, "state", sizeof(path));
if (!filestream_exists(path))
@ -800,7 +795,6 @@ static void check_proc_acpi_sysfs_battery(const char *node,
{
char basenode[512];
char path[PATH_MAX_LENGTH];
const char *base = proc_acpi_sysfs_battery_path;
char *buf = NULL;
char *ptr = NULL;
char *key = NULL;
@ -815,7 +809,8 @@ static void check_proc_acpi_sysfs_battery(const char *node,
int pct = -1;
/* Stat type. Avoid unknown or device supplies. Missing is considered System. */
fill_pathname_join_special(basenode, base, node, sizeof(basenode));
fill_pathname_join_special(basenode, PROC_ACPI_SYSFS_BATTERY_PATH,
node, sizeof(basenode));
fill_pathname_join_special(path, basenode, "scope", sizeof(path));
if (filestream_exists(path) != 0)
@ -876,14 +871,14 @@ static void check_proc_acpi_ac_adapter(const char * node, bool *have_ac)
{
char basenode[512];
char path[PATH_MAX_LENGTH];
const char *base = proc_acpi_ac_adapter_path;
char *buf = NULL;
char *ptr = NULL;
char *key = NULL;
char *val = NULL;
int64_t length = 0;
fill_pathname_join_special(basenode, base, node, sizeof(basenode));
fill_pathname_join_special(basenode, PROC_ACPI_AC_ADAPTER_PATH,
node, sizeof(basenode));
fill_pathname_join_special(path, basenode, "state", sizeof(path));
if (!filestream_exists(path))
return;
@ -909,8 +904,8 @@ static void check_proc_acpi_sysfs_ac_adapter(const char * node, bool *have_ac)
char path[1024];
int64_t length = 0;
char *buf = NULL;
const char *base = proc_acpi_sysfs_ac_adapter_path;
fill_pathname_join_special(path, base, "online", sizeof(path));
fill_pathname_join_special(path, PROC_ACPI_SYSFS_AC_ADAPTER_PATH,
"online", sizeof(path));
if (!filestream_exists(path))
return;
@ -968,10 +963,10 @@ static bool frontend_unix_powerstate_check_apm(
char *buf = NULL;
char *str = NULL;
if (!filestream_exists(proc_apm_path))
if (!filestream_exists(PROC_APM_PATH))
goto error;
if (filestream_read_file(proc_apm_path, (void**)&buf, &length) != 1)
if (filestream_read_file(PROC_APM_PATH, (void**)&buf, &length) != 1)
goto error;
ptr = &buf[0];
@ -1068,7 +1063,7 @@ static bool frontend_unix_powerstate_check_acpi(
retro_closedir(entry);
entry = retro_opendir(proc_acpi_ac_adapter_path);
entry = retro_opendir(PROC_ACPI_AC_ADAPTER_PATH);
if (!entry)
return false;
@ -1098,7 +1093,7 @@ static bool frontend_unix_powerstate_check_acpi_sysfs(
bool have_ac = false;
bool charging = false;
int valid_pct_idx = 0;
struct RDIR *entry = retro_opendir(proc_acpi_sysfs_battery_path);
struct RDIR *entry = retro_opendir(PROC_ACPI_SYSFS_BATTERY_PATH);
if (!entry)
goto error;
@ -1120,9 +1115,7 @@ static bool frontend_unix_powerstate_check_acpi_sysfs(
retro_closedir(entry);
entry = retro_opendir(proc_acpi_sysfs_ac_adapter_path);
if (entry)
if ((entry = retro_opendir(PROC_ACPI_SYSFS_AC_ADAPTER_PATH)))
{
check_proc_acpi_sysfs_ac_adapter(retro_dirent_get_name(entry), &have_ac);
retro_closedir(entry);
@ -1131,9 +1124,7 @@ static bool frontend_unix_powerstate_check_acpi_sysfs(
have_ac = false;
if (!have_battery)
{
*state = FRONTEND_POWERSTATE_NO_SOURCE;
}
else if (charging)
*state = FRONTEND_POWERSTATE_CHARGING;
else if (have_ac)
@ -1510,6 +1501,7 @@ static void frontend_unix_get_env(int *argc,
if (android_app->getStringExtra && jstr)
{
static char apk_dir[PATH_MAX_LENGTH];
const char *argv = (*env)->GetStringUTFChars(env, jstr, 0);
*apk_dir = '\0';
@ -1715,12 +1707,16 @@ static void frontend_unix_get_env(int *argc,
android_app->activity->clazz, android_app->isAndroidTV);
if (jbool != JNI_FALSE)
is_android_tv_device = true;
g_platform_android_flags |= PLAT_ANDROID_FLAG_ANDROID_TV_DEVICE;
}
frontend_android_get_name(device_model, sizeof(device_model));
system_property_get("getprop", "ro.product.id", device_id);
/* Check if we are a game console device */
if (device_is_game_console(device_model))
g_platform_android_flags |= PLAT_ANDROID_FLAG_GAME_CONSOLE_DEVICE;
/* Set automatic default values per device */
if (device_is_xperia_play(device_model))
g_defaults.settings_out_latency = 128;
@ -1754,7 +1750,8 @@ static void frontend_unix_get_env(int *argc,
*
* */
if (device_is_game_console(device_model) || device_is_android_tv())
if ( (g_platform_android_flags & PLAT_ANDROID_FLAG_GAME_CONSOLE_DEVICE)
|| (g_platform_android_flags & PLAT_ANDROID_FLAG_ANDROID_TV_DEVICE))
{
g_defaults.overlay_set = true;
g_defaults.overlay_enable = false;