Ejemplo n.º 1
0
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)
	}
}
Ejemplo n.º 2
0
func startHandler(w http.ResponseWriter, r *http.Request) {
	config, err := config.GetConfig()
	if err != nil {
		log.Panic(err)
	}
	emu_name := r.URL.Query().Get("name")
	if len(emu_name) == 0 {
		w.WriteHeader(http.StatusNotFound)
		return
	}
	emulator_binary := filepath.Join(config.SDKLocation, "tools", "emulator")
	go command.RunCommand(emulator_binary, "-avd", emu_name)
}