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, } } }
func PrintDeviceInfoAndError(descriptor adb.DeviceDescriptor) { device := adb.NewDeviceClient(adb.ClientConfig{}, descriptor) if err := PrintDeviceInfo(device); err != nil { log.Println(err) } }
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) }