android

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: Apache-2.0 Imports: 12 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

func SetupLayer added in v1.6.0

func SetupLayer(ctx context.Context, d Device, appPkg, layerPkg, layer string, vulkan bool) (app.Cleanup, error)

SetupLayer initializes d to use either a Vulkan or GLES layer from layerPkg limited to the app with package appPkg using the system settings and returns a cleanup to remove the layer settings.

func SupportsLayersViaSystemSettings added in v1.6.0

func SupportsLayersViaSystemSettings(d Device) bool

SupportsLayersViaSystemSettings returns whether the given device supports loading GLES and Vulkan layers via the system settings.

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 CustomExtras added in v1.1.0

type CustomExtras []string

CustomExtras is a list of custom intent extras

func (CustomExtras) Flags added in v1.1.0

func (e CustomExtras) 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)
	// InstalledPackage returns information about a single installed package on the device.
	InstalledPackage(ctx context.Context, name string) (*InstalledPackage, error)
	// UnlockScreen returns true if it managed to turn on and unlock the screen.
	UnlockScreen(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
	// NativeBridgeABI returns the native ABI for the given emulated ABI for the
	// device by consulting the ro.dalvik.vm.isa.<emulated_isa>=<native_isa>
	// system properties. If there is no native ABI for the given ABI, then abi
	// is simply returned.
	NativeBridgeABI(ctx context.Context, abi *device.ABI) *device.ABI
	// ForceStop stops the everything associated with the given package.
	ForceStop(ctx context.Context, pkg string) error
	// SystemProperty returns the system property in string.
	SystemProperty(ctx context.Context, name string) (string, error)
	// SetSystemProperty sets the system property with the given string value.
	SetSystemProperty(ctx context.Context, name, value string) error
	// SystemSetting returns the system setting with the given namespaced key.
	SystemSetting(ctx context.Context, namespace, key string) (string, error)
	// SetSystemSetting sets the system setting with with the given namespaced
	// key to value.
	SetSystemSetting(ctx context.Context, namespace, key, value string) error
	// DeleteSystemSetting removes the system setting with with the given
	// namespaced key.
	DeleteSystemSetting(ctx context.Context, namespace, key string) error
	// StartPerfettoTrace starts a perfetto trace.
	StartPerfettoTrace(ctx context.Context, config *perfetto_pb.TraceConfig, out string, stop task.Signal) 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) AppDir added in v1.3.1

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

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

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) GrantExternalStorageRW added in v1.1.0

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

GrantExternalStorageRW gives an installed package read and write permissions for external storage, this is mainly used to give an apk access to a pushed OBB file.

func (*InstalledPackage) OBBExists added in v1.1.0

func (p *InstalledPackage) OBBExists(ctx context.Context) bool

OBBExists checks whether an OBB file exists in the matching location for this APK on the device's external storage.

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) PullOBB added in v1.1.0

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

PullOBB pulls the matching OBB file from the device's external storage to the specified local directory.

func (*InstalledPackage) PushOBB added in v1.1.0

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

PushOBB places a OBB file to the correct location for an APK to access.

func (*InstalledPackage) RemoveOBB added in v1.1.0

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

RemoveOBB removes the OBB file for a specific package from external storage.

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