代码拉取完成,页面将自动刷新
package androidutils
import (
"errors"
"regexp"
"strconv"
)
var (
ErrPackageNotExist = errors.New("package not exist")
)
var (
rePkgPath = regexp.MustCompile(`codePath=([^\s]+)`)
reVerCode = regexp.MustCompile(`versionCode=(\d+)`)
reVerName = regexp.MustCompile(`versionName=([^\s]+)`)
)
type PackageInfo struct {
Name string
Path string
Version struct {
Code int
Name string
}
}
// StatPackage returns PackageInfo
// If package not found, err will be ErrPackageNotExist
func StatPackage(packageName string) (pi PackageInfo, err error) {
pi.Name = packageName
out, err := runShell("dumpsys", "package", packageName)
if err != nil {
return
}
matches := rePkgPath.FindStringSubmatch(out)
if len(matches) == 0 {
err = ErrPackageNotExist
return
}
pi.Path = matches[1]
matches = reVerCode.FindStringSubmatch(out)
if len(matches) == 0 {
err = ErrPackageNotExist
return
}
pi.Version.Code, _ = strconv.Atoi(matches[1])
matches = reVerName.FindStringSubmatch(out)
if len(matches) == 0 {
err = ErrPackageNotExist
return
}
pi.Version.Name = matches[1]
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。