android

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2017 License: Apache-2.0 Imports: 10 Imported by: 42

Documentation

Overview

Package android contains support for dealing with android devices.

Index

Constants

View Source
const (
	// Verbose represents the 'V' logcat message priority.
	Verbose = LogcatPriority(iota)
	// Debug represents the 'D' logcat message priority.
	Debug
	// Info represents the 'I' logcat message priority.
	Info
	// Warning represents the 'W' logcat message priority.
	Warning
	// Error represents the 'E' logcat message priority.
	Error
	// Fatal represents the 'F' logcat message priority.
	Fatal
)

Variables

View Source
var ErrProcessNotFound = fmt.Errorf("Process not found")

ErrProcessNotFound is returned by InstalledPackage.Pid when no running process of the package is found.

Functions

This section is empty.

Types

type ActionExtra

type ActionExtra interface {
	// Flags returns the formatted flags to pass to the Android am command.
	Flags() []string
}

ActionExtra is the interface implemented by intent extras.

type ActivityAction

type ActivityAction struct {
	// The action name.
	// Example: android.intent.action.MAIN
	Name string

	// The package that owns this activity action.
	Package *InstalledPackage

	// The activity that performs the action.
	// Example:  FooBarAction
	Activity string
}

ActivityAction represents an Android action that can be sent as an intent to an activity.

func (*ActivityAction) Component

func (a *ActivityAction) Component() string

Component returns the component name with package name prefix. For example: "com.example.app/.ExampleActivity" or "com.example.app/com.foo.ExampleActivity"

func (*ActivityAction) String

func (a *ActivityAction) String() string

type ActivityActions

type ActivityActions []*ActivityAction

ActivityActions is a list of activity actions.

func (ActivityActions) FindByName

func (l ActivityActions) FindByName(action, activity string) *ActivityAction

FindByName returns the service action with the specified names, or nil if no action with the matching names is found.

type BoolExtra

type BoolExtra struct {
	Key   string
	Value bool
}

BoolExtra represents an extra with a bool value.

func (BoolExtra) Flags

func (e BoolExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

type Device

type Device interface {
	bind.Device
	// InstallAPK installs the specified APK to the device. If reinstall is true
	// and the package is already installed on the device then it will be replaced.
	InstallAPK(ctx context.Context, path string, reinstall bool, grantPermissions bool) error
	// SELinuxEnforcing returns true if the device is currently in a
	// SELinux enforcing mode, or false if the device is currently in a SELinux
	// permissive mode.
	SELinuxEnforcing(ctx context.Context) (bool, error)
	// SetSELinuxEnforcing changes the SELinux-enforcing mode.
	SetSELinuxEnforcing(ctx context.Context, enforce bool) error
	// StartActivity launches the specified action.
	StartActivity(ctx context.Context, a ActivityAction, extras ...ActionExtra) error
	// StartActivityForDebug launches an activity in debug mode.
	StartActivityForDebug(ctx context.Context, a ActivityAction, extras ...ActionExtra) error
	// StartService launches the specified service.
	StartService(ctx context.Context, a ServiceAction, extras ...ActionExtra) error
	// Pushes the local file to the remote one.
	Push(ctx context.Context, local, remote string) error
	// Pulls the remote file to the local one.
	Pull(ctx context.Context, remote, local string) error
	// KeyEvent simulates a key-event on the device.
	KeyEvent(ctx context.Context, key KeyCode) error
	// SendEvent simulates low-level user-input to the device.
	SendEvent(ctx context.Context, deviceID, eventType, eventCode, value int) error
	// SendTouch simulates touch-screen press or release.
	SendTouch(ctx context.Context, deviceID, x, y int, pressed bool)
	// GetTouchDimensions returns the resolution of the touch sensor.
	// This may be different to the dimensions of the LCD screen.
	GetTouchDimensions(ctx context.Context) (deviceID, minX, maxX, minY, maxY int, ok bool)
	// GetScreenDimensions returns the resolution of the display.
	GetScreenDimensions(ctx context.Context) (orientation, width, height int, ok bool)
	// InstalledPackages returns the sorted list of installed packages on the device.
	InstalledPackages(ctx context.Context) (InstalledPackages, error)
	// IsScreenOn returns true if the device's screen is currently on.
	IsScreenOn(ctx context.Context) (bool, error)
	// TurnScreenOn turns the device's screen on.
	TurnScreenOn(ctx context.Context) error
	// TurnScreenOff turns the device's screen off.
	TurnScreenOff(ctx context.Context) error
	// IsShowingLockscreen returns true if the device's lockscreen is currently showing.
	IsShowingLockscreen(ctx context.Context) (bool, error)
	// Logcat writes all logcat messages reported by the device to the chan msgs,
	// blocking until the context is stopped.
	Logcat(ctx context.Context, msgs chan<- LogcatMessage) error
}

Device extends the bind.Device interface with capabilities specific to android devices.

type FloatExtra

type FloatExtra struct {
	Key   string
	Value float32
}

FloatExtra represents an extra with a float value.

func (FloatExtra) Flags

func (e FloatExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

type InstalledPackage

type InstalledPackage struct {
	Name            string          // Name of the package.
	Device          Device          // The device this package is installed on.
	ActivityActions ActivityActions // The activity actions this package supports.
	ServiceActions  ServiceActions  // The service actions this package supports.
	ABI             *device.ABI     // The ABI of the package or empty
	Debuggable      bool            // Whether the package is debuggable or not
	VersionCode     int             // The version code as reported by the manifest.
	VersionName     string          // The version name as reported by the manifest.
	MinSDK          int             // The minimum SDK reported by the manifest.
	TargetSdk       int             // The target SDK reported by the manifest.
}

InstalledPackage describes a package installed on a device.

func (*InstalledPackage) ClearCache

func (p *InstalledPackage) ClearCache(ctx context.Context) error

ClearCache deletes all data associated with a package.

func (*InstalledPackage) FileDir

func (p *InstalledPackage) FileDir(ctx context.Context) (string, error)

FileDir returns the absolute path of the installed packages files directory.

func (*InstalledPackage) Path

func (p *InstalledPackage) Path(ctx context.Context) (string, error)

Path returns the absolute path of the installed package on the device.

func (*InstalledPackage) Pid

func (p *InstalledPackage) Pid(ctx context.Context) (int, error)

Pid returns the PID of the newest (if pgrep exists) running process belonging to the given package.

func (*InstalledPackage) Pull

func (p *InstalledPackage) Pull(ctx context.Context, target string) error

Pull pulls the installed package from the device to the specified local directory.

func (*InstalledPackage) SetWrapProperties

func (p *InstalledPackage) SetWrapProperties(ctx context.Context, props ...string) error

SetWrapProperties sets the list of wrap-properties for the given installed package.

func (*InstalledPackage) Stop

func (p *InstalledPackage) Stop(ctx context.Context) error

Stop stops any activities belonging to the package from running on the device.

func (*InstalledPackage) String

func (p *InstalledPackage) String() string

String returns the package name.

func (*InstalledPackage) Uninstall

func (p *InstalledPackage) Uninstall(ctx context.Context) error

Uninstall uninstalls the package from the device.

func (*InstalledPackage) WrapProperties

func (p *InstalledPackage) WrapProperties(ctx context.Context) ([]string, error)

WrapProperties returns the list of wrap-properties for the given installed package.

type InstalledPackages

type InstalledPackages []*InstalledPackage

InstalledPackages is a list of installed packages.

func (InstalledPackages) FindByName

func (l InstalledPackages) FindByName(s string) *InstalledPackage

FindByName returns the installed package whose name exactly matches s.

func (InstalledPackages) FindByPartialName

func (l InstalledPackages) FindByPartialName(s string) InstalledPackages

FindByPartialName returns a list of installed packages whose name contains or equals s (case insensitive).

func (InstalledPackages) FindSingleByPartialName

func (l InstalledPackages) FindSingleByPartialName(s string) (*InstalledPackage, error)

FindSingleByPartialName returns the single installed package whose name contains or equals s (case insensitive). If none or more than one packages partially matches s then an error is returned. If a package exactly matches s then that is returned regardless of any partial matches.

func (InstalledPackages) Len

func (l InstalledPackages) Len() int

func (InstalledPackages) Less

func (l InstalledPackages) Less(i, j int) bool

func (InstalledPackages) Swap

func (l InstalledPackages) Swap(i, j int)

type IntExtra

type IntExtra struct {
	Key   string
	Value int
}

IntExtra represents an extra with an int value.

func (IntExtra) Flags

func (e IntExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

type LogcatMessage

type LogcatMessage struct {
	Timestamp time.Time
	Priority  LogcatPriority
	Tag       string
	ProcessID int
	ThreadID  int
	Message   string
}

LogcatMessage represents a single logcat message.

func (LogcatMessage) Log

func (m LogcatMessage) Log(ctx context.Context)

Log writes the LogcatMessage to ctx with the corresponding message severity.

type LogcatPriority

type LogcatPriority int

LogcatPriority represents the priority of a logcat message.

func (LogcatPriority) Severity

func (p LogcatPriority) Severity() log.Severity

Severity returns a Severity that closely corresponds to the priority.

type LongExtra

type LongExtra struct {
	Key   string
	Value int
}

LongExtra represents an extra with a long value.

func (LongExtra) Flags

func (e LongExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

type ServiceAction

type ServiceAction struct {
	// The action name.
	// Example: android.intent.action.MAIN
	Name string

	// The package that owns this service action.
	Package *InstalledPackage

	// The service that performs the action.
	// Example:  FooBarService
	Service string
}

ServiceAction represents an Android action that can be sent as an intent to a service.

func (*ServiceAction) Component

func (a *ServiceAction) Component() string

Component returns the component name with package name prefix. For example: "com.example.app/.ExampleService" or "com.example.app/com.foo.ExampleService"

func (*ServiceAction) String

func (a *ServiceAction) String() string

type ServiceActions

type ServiceActions []*ServiceAction

ServiceActions is a list of service actions.

func (ServiceActions) FindByName

func (l ServiceActions) FindByName(action, service string) *ServiceAction

FindByName returns the service action with the specified names, or nil if no action with the matching names is found.

type StringExtra

type StringExtra struct {
	Key   string
	Value string
}

StringExtra represents an extra with a string value.

func (StringExtra) Flags

func (e StringExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

type URIExtra

type URIExtra struct {
	Key   string
	Value string
}

URIExtra represents an extra with a URI value.

func (URIExtra) Flags

func (e URIExtra) Flags() []string

Flags returns the formatted flags to pass to the Android am command.

Directories

Path Synopsis
Package adb provides an interface to the Android Debug Bridge.
Package adb provides an interface to the Android Debug Bridge.
Package apk provides methods to get information (e.g.
Package apk provides methods to get information (e.g.
Package binaryxml is a package for dealing with the binary format of the android manifest.
Package binaryxml is a package for dealing with the binary format of the android manifest.
Package manifest supports reading and changing the android manifest xml file.
Package manifest supports reading and changing the android manifest xml file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL