termux

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalTimeout = 15 * time.Second

GlobalTimeout The global timeout to non-persistent and non-time-consuming operations

Functions

func AudioStreamVolume

func AudioStreamVolume(name string, volume int) error

AudioStreamVolume sets the volume of a given audio stream name

func Brightness

func Brightness(level uint8) error

Brightness sets the current brightness level from 0 to 255

func BrightnessAuto

func BrightnessAuto() error

BrightnessAuto sets the current brightness to auto

func ClipboardGet

func ClipboardGet() (string, error)

ClipboardGet gets the current content of the clipboard

func ClipboardSet

func ClipboardSet(val string) error

ClipboardSet sets the clipboard to the given value

func Dialog

func Dialog() error

Dialog pops up a dialog on the device Not implemented yet as the original api does not work on mmy device

func Download

func Download(desc string, title string, url string) error

Download calls the system download manager to download a URL

func Fingerprint

func Fingerprint() error

Fingerprint uses the fingerprint sensor on the device for authentication Not implemented as the original API does not work on my device

func Notification

func Notification(id string, opt NotificationOpt) error

Notification creates a new notification with the given id and options

func NotificationRemove

func NotificationRemove(id string) error

NotificationRemove removes the notification with the given id

func Record

func Record(duration int, outFile string) error

Record records from microphone, duration must be in seconds

func SMSSend

func SMSSend(numbers []string, text string) error

SMSSend sends a text message to the given recipient numbers

func Sensor

func Sensor(ctx context.Context, opt SensorWatchOpt) (<-chan []byte, error)

Sensor starts a sensor watch in a given context and options returns raw data bytes encoded with JSON

func SensorList

func SensorList() ([]string, error)

SensorList acquires a list of available sensors on the device

func Share

func Share(title string, data []byte, contentType string, useDefault bool, actionType ShareType) error

Share shares raw data bytes with the given content type, useDefault determines whether to use the default app if available

func ShareFile

func ShareFile(title string, path string, useDefault bool, actionType ShareType) error

ShareFile shares a file with MIME type determined by the file extension, useDefault determines whether to use the default app if available

func StopRecord

func StopRecord() error

StopRecord stop the recording process

func TakePhoto

func TakePhoto(cameraID string, outfile string) error

TakePhoto uses the device camera to take a photo and save the result to outfile cameraID is the id of the camera specified by the return of CameraInfo

func Toast

func Toast(text string, opts ToastOption) error

Toast creates a toast on the device

func TorchEnable

func TorchEnable(enabled bool) error

TorchEnable sets the current state of the device flashlight

func UpdatedLocation

func UpdatedLocation(ctx context.Context, provider LocationProvider) (<-chan struct {
	Location *LocationRecord
	Error    error
}, error)

UpdatedLocation acquires the real-time location of the device from a channel

func Vibrate

func Vibrate(ms int, force bool) error

Vibrate creates a vibration on the device, force means whether to vibrate even if the device is set to silent mode

func WallpaperFile

func WallpaperFile(path string, lockscreen bool) error

WallpaperFile sets the current wallpaper, main screen if lockscreen is false

func WallpaperURL

func WallpaperURL(url string, lockscreen bool) error

WallpaperURL sets the current wallpaper, main screen if lockscreen is false

func WifiEnable

func WifiEnable(enabled bool) error

WifiEnable sets the current enabled state of the device Wi-Fi

Types

type AudioInfoResponse

type AudioInfoResponse struct {
	JavaOutputSampleRate       string `json:"PROPERTY_OUTPUT_SAMPLE_RATE"`
	JavaOutputFramesPerBuffer  string `json:"PROPERTY_OUTPUT_FRAMES_PER_BUFFER"`
	AudioTrackOutputSampleRate int    `json:"AUDIOTRACK_NATIVE_OUTPUT_SAMPLE_RATE"`
	BluetoothA2DP              bool   `json:"BLUETOOTH_A2DP_IS_ON"`
	WiredHeadsetConnected      bool   `json:"WIREDHEADSET_IS_CONNECTED"`
}

AudioInfoResponse represents the current audio stream status

func AudioInfo

func AudioInfo() (*AudioInfoResponse, error)

AudioInfo acquires the current audio info

func (AudioInfoResponse) String added in v0.0.2

func (a AudioInfoResponse) String() string

type AudioStreamState

type AudioStreamState struct {
	Name      string `json:"stream"`
	Volume    int    `json:"volume"`
	MaxVolume int    `json:"max_volume"`
}

AudioStreamState represents the volume info of an audio stream

func AudioStreams

func AudioStreams() ([]AudioStreamState, error)

AudioStreams acquires all audio stream volume info from the device

func (AudioStreamState) String added in v0.0.2

func (a AudioStreamState) String() string

type BatteryStatusResponse

type BatteryStatusResponse struct {
	Health      string  `json:"health"`
	Percentage  int     `json:"percentage"`
	Plugged     string  `json:"plugged"`
	Status      string  `json:"status"`
	Temperature float64 `json:"temperature"`
}

BatteryStatusResponse represents the current battery status

func BatteryStatus

func BatteryStatus() (*BatteryStatusResponse, error)

BatteryStatus acquires the current audio info

func (BatteryStatusResponse) String added in v0.0.2

func (b BatteryStatusResponse) String() string

type CallLogPiece

type CallLogPiece struct {
	Name     string `json:"name"`
	Number   string `json:"phone_number"`
	Type     string `json:"type"`
	Date     string `json:"date"`
	Duration string `json:"duration"`
}

CallLogPiece represents one piece of call log

func CallLog

func CallLog(limit int, offset int) ([]CallLogPiece, error)

CallLog acquires call logs with a given limit and offset

func (CallLogPiece) String added in v0.0.2

func (c CallLogPiece) String() string

type CameraInfoPiece

type CameraInfoPiece struct {
	ID              string `json:"id"`
	Facing          string `json:"facing"`
	JPEGOutputSizes []struct {
		Width  int `json:"width"`
		Height int `json:"height"`
	} `json:"jpeg_output_sizes"`
	FocalLengths []float64 `json:"focal_lengths"`
	AEModes      []string  `json:"auto_exposure_modes"`
	PhysicalSize struct {
		Width  float64 `json:"width"`
		Height float64 `json:"height"`
	} `json:"physical_size"`
	Capabilities []string `json:"capabilities"`
}

CameraInfoPiece represent the info of one camera on the device

func CameraInfo

func CameraInfo() ([]CameraInfoPiece, error)

CameraInfo gets the information of available cameras on the device

func (CameraInfoPiece) String added in v0.0.2

func (c CameraInfoPiece) String() string

type ContactPiece

type ContactPiece struct {
	Name   string `json:"name"`
	Number string `json:"number"`
}

ContactPiece represents one contact info

func ContactList

func ContactList() ([]ContactPiece, error)

ContactList gets all contact from the device

func (ContactPiece) String added in v0.0.2

func (c ContactPiece) String() string

type LocationProvider

type LocationProvider string

LocationProvider enumerates the location sources provided by the device

const (
	// GPS acquire location with GPS
	GPS LocationProvider = "gps"
	// Network acquire location using current network
	Network LocationProvider = "network"
	// Passive acquire location using passive methods
	Passive LocationProvider = "passive"
)

type LocationRecord

type LocationRecord struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Altitude  float64 `json:"altitude"`
	Accuracy  float64 `json:"accuracy"`
	Bearing   float64 `json:"bearing"`
	Speed     float64 `json:"speed"`
	ElapsedMS int     `json:"elapsedMs"`
	Provider  string  `json:"provider"`
}

LocationRecord represents a location record provided by the device

func LastLocation

func LastLocation(ctx context.Context, provider LocationProvider) (*LocationRecord, error)

LastLocation acquires the last known location of the device

func Location

func Location(ctx context.Context, provider LocationProvider) (*LocationRecord, error)

Location acquires the current location of the device

func (LocationRecord) String added in v0.0.2

func (l LocationRecord) String() string

type NotificationButton

type NotificationButton struct {
	Text   string
	Action string
}

NotificationButton represents a button shown in the notification bar

type NotificationListResponse added in v0.0.2

type NotificationListResponse struct {
	ID          int    `json:"id"`
	Tag         string `json:"tag"`
	Key         string `json:"key"`
	Group       string `json:"group"`
	PackageName string `json:"packageName"`
	Title       string `json:"title"`
	Content     string `json:"content"`
	When        string `json:"when"`
}

NotificationListResponse represents a notification

func NotificationList added in v0.0.2

func NotificationList() ([]NotificationListResponse, error)

func (NotificationListResponse) String added in v0.0.2

func (n NotificationListResponse) String() string

type NotificationOpt

type NotificationOpt struct {
	Content  string
	Sound    bool
	Title    string
	Vibrate  []int32
	Priority NotificationPriority
	LED      struct {
		Color string
		On    int
		Off   int
	}
	Action       string
	DeleteAction string
	Btn1         NotificationButton
	Btn2         NotificationButton
	Btn3         NotificationButton
}

NotificationOpt represents the options of a notification

type NotificationPriority

type NotificationPriority string

NotificationPriority enumerates the priority level of the notification

const (
	// Max notification priority
	Max NotificationPriority = "max"
	// High notification priority
	High NotificationPriority = "high"
	// Default notification priority
	Default NotificationPriority = "default"
	// Low notification priority
	Low NotificationPriority = "low"
	// Min notification priority
	Min NotificationPriority = "min"
)

type RecordInfo

type RecordInfo struct {
	IsRecording bool   `json:"isRecording"`
	OutputFile  string `json:"outputFile"`
}

RecordInfo represent the current state of recording process

func GetRecordInfo

func GetRecordInfo() (RecordInfo, error)

GetRecordInfo returns the current state of the recording process

type SMS

type SMS struct {
	ThreadID int    `json:"threadid"` // ThreadID is the unique identifier of the SMS thread
	Type     string `json:"type"`     // Type is the type of the SMS box
	Read     bool   `json:"read"`     // Read is the flag indicating whether the SMS has been read
	Number   string `json:"number"`   // Number is the phone number of the sender
	Received string `json:"received"` // Received is the time when the SMS was received
	Body     string `json:"body"`     // Body is the content of the SMS
	ID       int    `json:"_id"`      // ID is the unique identifier of the SMS
}

SMS represents a piece of SMS Example:

{
  "threadid": 4,
  "type": "inbox",
  "read": true,
  "number": "+1000001",
  "received": "2023-08-15 10:01:40",
  "body": "Hello World!",
  "_id": 3
}

func SMSList

func SMSList(limit int, offset int, box SMSBoxType) ([]SMS, error)

SMSList acquires a list of the received SMS in the given SMS box with a given limit and offset

func (SMS) String added in v0.0.2

func (s SMS) String() string

type SMSBoxType

type SMSBoxType int

SMSBoxType enumerates available sms box types

const (
	// All sms box type
	All SMSBoxType = 0
	// Inbox sms box type
	Inbox SMSBoxType = 1
	// Sent sms box type
	Sent SMSBoxType = 2
	// Draft sms box type
	Draft SMSBoxType = 3
	// Outbox sms box type
	Outbox SMSBoxType = 4
)

type SensorWatchOpt

type SensorWatchOpt struct {
	Limit      int
	DelayMS    int
	SensorList []string
}

SensorWatchOpt represents the options to a Sensor call

type ShareType

type ShareType = string

ShareType represent the action of the share, defaults to edit

const (
	// View share type
	View ShareType = "view"
	// Edit share type
	Edit ShareType = "edit"
	// Send share type
	Send ShareType = "send"
)

type ToastOption

type ToastOption struct {
	BGColor   string
	FontColor string
	Position  ToastPosition
	Short     bool
}

ToastOption represents the optional options to a toast

type ToastPosition

type ToastPosition string

ToastPosition enumerates current position of the toast

const (
	// Top lifts the toast ot the top of the screen
	Top ToastPosition = "top"
	// Middle is the default position of the toast
	Middle ToastPosition = "middle"
	// Bottom puts the toast to the bottom of the screen
	Bottom ToastPosition = "bottom"
)

type WifiAP

type WifiAP struct {
	BSSID     string `json:"bssid"`
	FreqMHZ   int    `json:"frequency_mhz"`
	RSSI      int    `json:"rssi"`
	SSID      string `json:"ssid"`
	TimeStamp int64  `json:"timestamp"`
	// CenterFreqMHZ not used for 20Mhz bands
	CenterFreqMHZ    int    `json:"center_frequency_mhz"`
	ChannelBandwidth string `json:"channel_bandwidth_mhz"`
}

WifiAP represents a discovered AP in a Wi-Fi scan

func WifiScan

func WifiScan() ([]WifiAP, error)

WifiScan scans for available networks

func (WifiAP) String added in v0.0.2

func (w WifiAP) String() string

type WifiConnection

type WifiConnection struct {
	BSSID           string `json:"bssid"`
	FreqMHZ         int    `json:"frequency_mhz"`
	IP              string `json:"ip"`
	LinkSpeedMbps   int    `json:"link_speed_mbps"`
	MACAddr         string `json:"mac_address"`
	NetworkID       int    `json:"network_id"`
	RSSI            int    `json:"rssi"`
	SSID            string `json:"ssid"`
	SSIDHidden      bool   `json:"ssid_hidden"`
	SupplicantState string `json:"supplicant_state"`
}

WifiConnection represents the current connection info of the device Wi-Fi interface

func WifiConnectionState

func WifiConnectionState() (*WifiConnection, error)

WifiConnectionState returns the current Wi-Fi connection state of the device

func (WifiConnection) String added in v0.0.2

func (w WifiConnection) String() string

Jump to

Keyboard shortcuts

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