Skip to content

Commit

Permalink
Support drag & drop a file to transfer it to device
Browse files Browse the repository at this point in the history
Signed-off-by: npes87184 <[email protected]>
  • Loading branch information
npes87184 committed Aug 12, 2018
1 parent f87ebdd commit 57e42ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 24 additions & 9 deletions app/src/file_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string.h>
#include "command.h"
#include "device.h"
#include "lockutil.h"
#include "log.h"

Expand Down Expand Up @@ -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;

Expand All @@ -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, &current_apk);
bool non_empty = file_queue_take(&file_handler->queue, &current_file);
SDL_assert(non_empty);
#else
file_queue_take(&file_handler->queue, &current_apk);
file_queue_take(&file_handler->queue, &current_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;
}
Expand Down

0 comments on commit 57e42ac

Please sign in to comment.