Ejemplo n.º 1
0
func NewGoadbDeviceClientFactory(clientConfig goadb.ClientConfig, deviceSerial string, deviceDisconnectedHandler func()) DeviceClientFactory {
	deviceDescriptor := goadb.DeviceWithSerial(deviceSerial)

	return func() DeviceClient {
		return goadbDeviceClient{
			DeviceClient:              goadb.NewDeviceClient(clientConfig, deviceDescriptor),
			deviceDisconnectedHandler: deviceDisconnectedHandler,
		}
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	client := adb.NewHostClient(adb.ClientConfig{})

	fmt.Println("Starting server…")
	adb.StartServer()

	serverVersion, err := client.GetServerVersion()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Server version:", serverVersion)

	devices, err := client.ListDevices()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Devices:")
	for _, device := range devices {
		fmt.Printf("\t%+v\n", *device)
	}

	PrintDeviceInfoAndError(adb.AnyDevice())
	PrintDeviceInfoAndError(adb.AnyLocalDevice())
	PrintDeviceInfoAndError(adb.AnyUsbDevice())

	serials, err := client.ListDeviceSerials()
	if err != nil {
		log.Fatal(err)
	}
	for _, serial := range serials {
		PrintDeviceInfoAndError(adb.DeviceWithSerial(serial))
	}

	fmt.Println()
	fmt.Println("Watching for device state changes.")
	watcher := adb.NewDeviceWatcher(adb.ClientConfig{})
	for event := range watcher.C() {
		fmt.Printf("\t[%s]%+v\n", time.Now(), event)
	}
	if watcher.Err() != nil {
		printErr(watcher.Err())
	}

	//fmt.Println("Killing server…")
	//client.KillServer()
}
Ejemplo n.º 3
0
func mountDevice(serial string, context context.Context) {
	eventLog := cli.NewEventLog(appName, "device:"+serial)

	defer func() {
		eventLog.Debugf("device mount process finished: %s", serial)
		eventLog.Finish()
	}()

	adbClient := goadb.NewDeviceClient(config.ClientConfig(), goadb.DeviceWithSerial(serial))
	deviceInfo, err := adbClient.GetDeviceInfo()
	if err != nil {
		eventLog.Errorf("error getting device info for %s: %s", serial, err)
		return
	}

	mountpoint, err := cli.NewMountpointForDevice(deviceInfo, config.MountRoot, serial)
	if err != nil {
		eventLog.Errorf("error creating mountpoint for %s: %s", serial, err)
		return
	}
	defer RemoveLoggingError(mountpoint)

	eventLog.Infof("mounting %s on %s", serial, mountpoint)
	cmd := NewMountProcess(config.PathToAdbfs, cli.AdbfsConfig{
		BaseConfig:   config.BaseConfig,
		DeviceSerial: serial,
		Mountpoint:   mountpoint,
	})

	eventLog.Debugf("launching adbfs: %s", CommandLine(cmd))
	if err := cmd.Start(); err != nil {
		eventLog.Errorf("error starting adbfs process: %s", err)
		return
	}

	eventLog.Infof("device %s mounted with PID %d", serial, cmd.Process.Pid)

	// If we're told to stop, kill the mount process.
	go func() {
		<-context.Done()
		cmd.Process.Kill()
	}()

	handlerBinding := map[string]string{
		cli.PathHandlerVar:   mountpoint,
		cli.SerialHandlerVar: serial,
		cli.ModelHandlerVar:  deviceInfo.Model,
	}
	cli.FireHandlers(config.OnMountHandlers, handlerBinding)
	defer cli.FireHandlers(config.OnUnmountHandlers, handlerBinding)

	if err := cmd.Wait(); err != nil {
		if err, ok := err.(*exec.ExitError); ok {
			eventLog.Errorf("adbfs exited with %+v", err)
		} else {
			eventLog.Errorf("lost connection with adbfs process:", err)
		}
		return
	}

	eventLog.Infof("mount process for device %s stopped", serial)
}