diff --git a/app/src/device.h b/app/src/device.h index d01d6ed294..125dda3a91 100644 --- a/app/src/device.h +++ b/app/src/device.h @@ -7,6 +7,7 @@ #include "net.h" #define DEVICE_NAME_FIELD_LENGTH 64 +#define DEVICE_SDCARD_PATH "/sdcard/" // name must be at least DEVICE_NAME_FIELD_LENGTH bytes SDL_bool device_read_info(socket_t device_socket, char *name, struct size *frame_size); diff --git a/app/src/file_handler.c b/app/src/file_handler.c index 449946fb10..cc37e7be68 100644 --- a/app/src/file_handler.c +++ b/app/src/file_handler.c @@ -2,6 +2,7 @@ #include #include "command.h" +#include "device.h" #include "lockutil.h" #include "log.h" @@ -113,6 +114,11 @@ SDL_bool file_handler_do(struct file_handler *file_handler, const char *file) { return res; } +static int is_apk(const char *file) { + const char *ext = strrchr(file, '.'); + return ext && !strcmp(ext, ".apk"); +} + static int run_file_handler(void *data) { struct file_handler *file_handler = data; @@ -126,25 +132,34 @@ static int run_file_handler(void *data) { mutex_unlock(file_handler->mutex); break; } - char *current_apk; + char *current_file; + char cmd[16]; + process_t process; #ifdef BUILD_DEBUG - bool non_empty = file_queue_take(&file_handler->queue, ¤t_apk); + bool non_empty = file_queue_take(&file_handler->queue, ¤t_file); SDL_assert(non_empty); #else - file_queue_take(&file_handler->queue, ¤t_apk); + file_queue_take(&file_handler->queue, ¤t_file); #endif - LOGI("Installing %s...", current_apk); - process_t process = adb_install(file_handler->serial, current_apk); + LOGI("Processing %s...", current_file); + if (is_apk(current_file)) { + process = adb_install(file_handler->serial, current_file); + strncpy(cmd, "adb install", sizeof(cmd)); + } else { + process = adb_push(file_handler->serial, current_file, DEVICE_SDCARD_PATH); + strncpy(cmd, "adb push", sizeof(cmd)); + } + cmd[sizeof(cmd) - 1] = '\0'; file_handler->current_process = process; mutex_unlock(file_handler->mutex); - if (process_check_success(process, "adb install")) { - LOGI("%s installed successfully", current_apk); + if (process_check_success(process, cmd)) { + LOGI("Process %s successfully", current_file); } else { - LOGE("Failed to install %s", current_apk); + LOGE("Failed to process %s", current_file); } - SDL_free(current_apk); + SDL_free(current_file); } return 0; }