int install_app(transport_type transport, char* serial, int argc, char** argv) { struct stat st; int err; const char *const WHERE = "/data/local/tmp/%s"; char to[PATH_MAX]; char* filename = argv[argc - 1]; const char* p; p = adb_dirstop(filename); if (p) { p++; snprintf(to, sizeof to, WHERE, p); } else { snprintf(to, sizeof to, WHERE, filename); } if (p[0] == '\0') { } err = stat(filename, &st); if (err != 0) { fprintf(stderr, "can't find '%s' to install\n", filename); return 1; } if (!S_ISREG(st.st_mode)) { fprintf(stderr, "can't install '%s' because it's not a file\n", filename); return 1; } if (!(err = do_sync_push(filename, to, 1 /* verify APK */))) { /* file in place; tell the Package Manager to install it */ argv[argc - 1] = to; /* destination name, not source location */ pm_command(transport, serial, argc, argv); delete_file(transport, serial, to); } return err; }
int install_app(transport_type transport, char* serial, int argc, char** argv) { static const char *const DATA_DEST = "/data/local/tmp/%s"; static const char *const SD_DEST = "/sdcard/tmp/%s"; const char* where = DATA_DEST; char apk_dest[PATH_MAX]; char verification_dest[PATH_MAX]; char* apk_file; char* verification_file = NULL; int file_arg = -1; int err; int i; int verify_apk = 1; for (i = 1; i < argc; i++) { if (*argv[i] != '-') { file_arg = i; break; } else if (!strcmp(argv[i], "-i")) { // Skip the installer package name. i++; } else if (!strcmp(argv[i], "-s")) { where = SD_DEST; } else if (!strcmp(argv[i], "--algo")) { verify_apk = 0; i++; } else if (!strcmp(argv[i], "--iv")) { verify_apk = 0; i++; } else if (!strcmp(argv[i], "--key")) { verify_apk = 0; i++; } } if (file_arg < 0) { fprintf(stderr, "can't find filename in arguments\n"); return 1; } else if (file_arg + 2 < argc) { fprintf(stderr, "too many files specified; only takes APK file and verifier file\n"); return 1; } apk_file = argv[file_arg]; if (file_arg != argc - 1) { verification_file = argv[file_arg + 1]; } if (check_file(apk_file) || check_file(verification_file)) { return 1; } snprintf(apk_dest, sizeof apk_dest, where, get_basename(apk_file)); if (verification_file != NULL) { snprintf(verification_dest, sizeof(verification_dest), where, get_basename(verification_file)); if (!strcmp(apk_dest, verification_dest)) { fprintf(stderr, "APK and verification file can't have the same name\n"); return 1; } } err = do_sync_push(apk_file, apk_dest, verify_apk); if (err) { goto cleanup_apk; } else { argv[file_arg] = apk_dest; /* destination name, not source location */ } if (verification_file != NULL) { err = do_sync_push(verification_file, verification_dest, 0 /* no verify APK */); if (err) { goto cleanup_apk; } else { argv[file_arg + 1] = verification_dest; /* destination name, not source location */ } } pm_command(transport, serial, argc, argv); cleanup_apk: if (verification_file != NULL) { delete_file(transport, serial, verification_dest); } delete_file(transport, serial, apk_dest); return err; }