device — 设备
import "gomaton.dev/sdk/device"
Package device 读写设备信息与状态(胶水:shell + 框架桥)。
能力总览:
- 屏幕/显示:Size / CurrentSize 分辨率、Density DPI、Rotation 朝向、 IsScreenOn / ScreenUnlocked 亮屏与锁屏、Wake / Sleep 常亮开关、SetDisplayPower 亮灭屏。
- 亮度:GetBrightness / SetBrightness(0..255)、GetBrightnessMode / SetBrightnessMode 自动手动。
- 音量/震动:GetVolume / SetVolume 按音量流、Vibrate / CancelVibration 震动(走框架桥,破部分 ROM 的音量拦截)。
- 设备标识:Model 型号、Serial 序列号、AndroidVersion 系统版本、GetAndroidId、GetWifiMac、Imei(A10+ 非 root 取不到)。
- 电量/内存:Battery 电量、BatteryStatus 充电状态、MemInfo 总量/可用。
- 网络:GetIp 局域网 IP、GetWifiMac。
- 前台/通知:Foreground 当前前台窗口、Notifications 读通知栏。
- 电源:Reboot 重启(需 root)。
AndroidVersion
func AndroidVersion() string
AndroidVersion 系统版本号(ro.build.version.release,如 "14")。
Battery
func Battery() int
Battery 电量百分比。
BatteryStatus
func BatteryStatus() int
BatteryStatus 电池状态:1 未知 2 充电 3 放电 4 不充 5 满。
CancelVibration
func CancelVibration() error
CancelVibration 停止震动。
CurrentSize
func CurrentSize() (int, int)
CurrentSize 当前朝向下的分辨率(横屏交换)。
Density
func Density() int
Density 屏幕 DPI。
Foreground
func Foreground() string
Foreground 当前前台窗口(pkg/Activity)。
GetAndroidId
func GetAndroidId() string
GetAndroidId ANDROID_ID。
GetBrightness
func GetBrightness() int
GetBrightness 当前亮度 0..255。
GetBrightnessMode
func GetBrightnessMode() int
GetBrightnessMode 亮度模式:0 手动 1 自动。
GetIp
func GetIp() string
GetIp 局域网 IP。
GetVolume
func GetVolume(stream int) (int, int)
GetVolume 某音量流的 (当前, 最大);走框架桥。
GetWifiMac
func GetWifiMac() string
GetWifiMac WiFi MAC。
Imei
func Imei() string
Imei IMEI(Android 10+ 非 root 取不到,返回空)。
IsScreenOn
func IsScreenOn() bool
IsScreenOn 屏幕是否亮着。
MemInfo
func MemInfo() (int, int)
MemInfo 内存 (总量 KB, 可用 KB)。
Model
func Model() string
Model 设备型号(ro.product.model)。
Notifications
func Notifications() []Notification
Notifications 读当前通知栏(best-effort)。
Reboot
func Reboot() error
Reboot 重启设备(需 root)。
Rotation
func Rotation() int
Rotation 屏幕旋转 0/1/2/3。
ScreenUnlocked
func ScreenUnlocked() bool
ScreenUnlocked 是否已解锁(粗判)。
Serial
func Serial() string
Serial 设备序列号(ro.serialno)。
SetBrightness
func SetBrightness(v int)
SetBrightness 设亮度 0..255(切手动)。
SetBrightnessMode
func SetBrightnessMode(auto bool)
SetBrightnessMode 设自动/手动。
SetDisplayPower
func SetDisplayPower(on bool)
SetDisplayPower 亮/灭屏。
SetVolume
func SetVolume(stream, v int)
SetVolume 设某音量流。
Size
func Size() (int, int)
Size 屏幕物理分辨率(宽, 高),不随旋转变化。
Sleep
func Sleep()
Sleep 取消常亮。
Vibrate
func Vibrate(ms int) error
Vibrate 震动 ms 毫秒(走框架桥)。
Wake
func Wake()
Wake 亮屏并保持常亮。