diff --git a/app/src/apkinstaller.c b/app/src/apkinstaller.c index eb76c92d..400de9c1 100644 --- a/app/src/apkinstaller.c +++ b/app/src/apkinstaller.c @@ -5,6 +5,7 @@ #include "command.h" #include "string.h" + // NOTE(adopi) this can be more generic: // it could be used with a command queue instead of a filename queue // then we would have a generic invoker (useful if we want to handle more async commands) @@ -83,6 +84,7 @@ void installer_destroy(struct installer *installer) { SDL_free((void *) installer->serial); installer->initialized = SDL_FALSE; installer->stopped = SDL_FALSE; + installer->current_process = PROCESS_NONE; } SDL_bool installer_push_apk(struct installer *installer, const char* apk) { @@ -100,6 +102,7 @@ SDL_bool installer_push_apk(struct installer *installer, const char* apk) { static SDL_bool process_install(struct installer *installer, const char* filename) { LOGI("%s will be installed",filename); process_t process = adb_install(installer->serial, filename); + installer->current_process = process; return process_check_success(process, "adb install"); } @@ -143,6 +146,13 @@ void installer_stop(struct installer *installer) { mutex_lock(installer->mutex); installer->stopped = SDL_TRUE; cond_signal(installer->event_cond); + if (installer->current_process == PROCESS_NONE) { + if (!cmd_terminate(installer->current_process)) { + LOGW("Cannot terminate install process"); + } + cmd_simple_wait(installer->current_process, NULL); + installer->current_process = PROCESS_NONE; + } mutex_unlock(installer->mutex); } diff --git a/app/src/apkinstaller.h b/app/src/apkinstaller.h index 7e072963..4024e40e 100644 --- a/app/src/apkinstaller.h +++ b/app/src/apkinstaller.h @@ -10,6 +10,7 @@ #include #include #include +#include "command.h" // NOTE(AdoPi) apk_queue and control_event can use a generic queue @@ -26,16 +27,18 @@ struct installer { SDL_cond *event_cond; SDL_bool stopped; SDL_bool initialized; + process_t current_process; struct apk_queue queue; }; -#define INSTALLER_INITIALIZER { \ - .serial = NULL, \ - .thread = NULL, \ - .mutex = NULL, \ - .event_cond = NULL, \ - .stopped = SDL_FALSE, \ - .initialized = SDL_FALSE \ +#define INSTALLER_INITIALIZER { \ + .serial = NULL, \ + .thread = NULL, \ + .mutex = NULL, \ + .event_cond = NULL, \ + .stopped = SDL_FALSE, \ + .initialized = SDL_FALSE, \ + .current_process = PROCESS_NONE \ }