blob: 329176e088a1e14859e8bb65ea41ac928c0881ea [file] [log] [blame]
// Copyright (C) 2015 The Android Open Source Project
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package adb
import "fmt"
// Port is the interface for sockets ports that can be forwarded from an Android
// Device to the local machine.
type Port interface {
// adbForwardString returns the "port specification" for the adb forward
// command. See:
// This method is hidden as its only use is for adb command-line parameters,
// which this package abstracts.
adbForwardString() string
// TCPPort represents a TCP/IP port on either the local machine or Android
// device. TCPPort implements the Port interface.
type TCPPort int
func (p TCPPort) adbForwardString() string {
return fmt.Sprintf("tcp:%d", p)
// NamedAbstractSocket represents an abstract UNIX domain socket name on either
// the local machine or Android device. NamedAbstractSocket implements the Port
// interface.
type NamedAbstractSocket string
func (p NamedAbstractSocket) adbForwardString() string {
return fmt.Sprintf("localabstract:%s", p)
// Forward will forward the specified device Port to the specified local Port.
func (d *Device) Forward(local, device Port) error {
_, err := run("-s", d.Serial, "forward", local.adbForwardString(), device.adbForwardString())
return err