Exemplo n.º 1
0
func doCommand(cmd string) error {
	conn, err := goadb.NewDialer("", *port).Dial()
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	if err := wire.SendMessageString(conn, cmd); err != nil {
		return err
	}

	status, err := conn.ReadStatus()
	if err != nil {
		return err
	}

	var msg string
	for err == nil {
		msg, err = wire.ReadMessageString(conn)
		if err == nil {
			fmt.Printf("%s> %s\n", status, msg)
		}
	}

	if err != io.EOF {
		return err
	}

	return nil
}
Exemplo n.º 2
0
/*
KillServer tells the server to quit immediately.

Corresponds to the command:
	adb kill-server
*/
func (c *HostClient) KillServer() error {
	conn, err := c.config.Dialer.Dial()
	if err != nil {
		return wrapClientError(err, c, "KillServer")
	}
	defer conn.Close()

	if err = wire.SendMessageString(conn, "host:kill"); err != nil {
		return wrapClientError(err, c, "KillServer")
	}

	return nil
}
Exemplo n.º 3
0
func (c *DeviceClient) getSyncConn() (*wire.SyncConn, error) {
	conn, err := c.dialDevice()
	if err != nil {
		return nil, err
	}

	// Switch the connection to sync mode.
	if err := wire.SendMessageString(conn, "sync:"); err != nil {
		return nil, err
	}
	if err := wire.ReadStatusFailureAsError(conn, "sync"); err != nil {
		return nil, err
	}

	return conn.NewSyncConn(), nil
}
Exemplo n.º 4
0
func connectToTrackDevices(dialer Dialer) (wire.Scanner, error) {
	conn, err := dialer.Dial()
	if err != nil {
		return nil, err
	}

	if err := wire.SendMessageString(conn, "host:track-devices"); err != nil {
		conn.Close()
		return nil, err
	}

	if err := wire.ReadStatusFailureAsError(conn, "host:track-devices"); err != nil {
		conn.Close()
		return nil, err
	}

	return conn, nil
}
Exemplo n.º 5
0
// dialDevice switches the connection to communicate directly with the device
// by requesting the transport defined by the DeviceDescriptor.
func (c *DeviceClient) dialDevice() (*wire.Conn, error) {
	conn, err := c.config.Dialer.Dial()
	if err != nil {
		return nil, err
	}

	req := fmt.Sprintf("host:%s", c.descriptor.getTransportDescriptor())
	if err = wire.SendMessageString(conn, req); err != nil {
		conn.Close()
		return nil, util.WrapErrf(err, "error connecting to device '%s'", c.descriptor)
	}

	if err = wire.ReadStatusFailureAsError(conn, req); err != nil {
		conn.Close()
		return nil, err
	}

	return conn, nil
}