func installJobWorker() { config, err := config.GetConfig() if err != nil { log.Panic(err) } for job := range installJobChannel { emulator_binary := filepath.Join(config.SDKLocation, "platform-tools", "adb") command.RunCommand(emulator_binary, "-s", job.EmuName, "install", "-r", job.TempFilePath) // fmt.Println(stdout.String()) //Run the apk //Get the package name using latest build tools' aapt build_tools_dir_path := filepath.Join(config.SDKLocation, "build-tools") build_tools_dir, err := ioutil.ReadDir(build_tools_dir_path) latest_build_tools := build_tools_dir[len(build_tools_dir)-1] aapt_binary := filepath.Join(build_tools_dir_path, latest_build_tools.Name(), "aapt") // fmt.Println("Running", aapt_binary, "on", temp_file_path) stdout, _, err := command.GetCommandResponse(aapt_binary, "dump", "badging", job.TempFilePath) if err != nil { log.Println(err) return } package_string_regex := regexp.MustCompile("package: name='(.+?)'") package_string_matches := package_string_regex.FindStringSubmatch(stdout.String()) if len(package_string_matches) < 2 { log.Println("Could not match package name") return } package_string := package_string_matches[1] activity_string_regex := regexp.MustCompile("launchable-activity: name='(.+?)'") activity_string_matches := activity_string_regex.FindStringSubmatch(stdout.String()) if len(package_string_matches) < 2 { log.Println("Could not match activity name") return } activity_string := activity_string_matches[1] // fmt.Println("Found package string", package_string, "-", activity_string) //Run the actual app adb_binary := filepath.Join(config.SDKLocation, "platform-tools", "adb") stdout, stderr, err := command.GetCommandResponse(adb_binary, "-s", job.EmuName, "shell", "am", "start", fmt.Sprintf("%s/%s", package_string, activity_string)) if err != nil { fmt.Println(err) } fmt.Println(stdout.String()) fmt.Println(stderr.String()) os.Remove(job.TempFilePath) } }
func listADBHandler(w http.ResponseWriter, r *http.Request) { config, err := config.GetConfig() if err != nil { log.Panic(err) } adb_binary := filepath.Join(config.SDKLocation, "platform-tools", "adb") stdout, _, _ := command.GetCommandResponse(adb_binary, "devices", "-l") var adbList []model.ADBDevice = make([]model.ADBDevice, 0) parser.UnmarshalADB(&adbList, stdout.String()) json, _ := json.MarshalIndent(adbList, "", "\t") w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, string(json)) }
func listAVDHandler(w http.ResponseWriter, r *http.Request) { config, err := config.GetConfig() if err != nil { log.Panic(err) } android_binary := filepath.Join(config.SDKLocation, "tools", "android") stdout, _, _ := command.GetCommandResponse(android_binary, "list", "avd") ms := strings.Split(stdout.String(), "---------") avd_list := make([]model.AVD, 0) for _, m := range ms { var avd model.AVD parser.UnmarshalAVD(&avd, m) avd_list = append(avd_list, avd) } json, _ := json.MarshalIndent(avd_list, "", "\t") w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, string(json)) }