chore(tools): device-check 兼容 Flyme 解冻,重试时延长等待
This commit is contained in:
@@ -79,19 +79,21 @@ $creates = 0
|
|||||||
# Flyme 有时不会立刻杀掉带前台服务的进程,导致抓不到启动日志:确认进程消失 + 最多重试两次
|
# Flyme 有时不会立刻杀掉带前台服务的进程,导致抓不到启动日志:确认进程消失 + 最多重试两次
|
||||||
for ($attempt = 1; $attempt -le 2; $attempt++) {
|
for ($attempt = 1; $attempt -le 2; $attempt++) {
|
||||||
& adb -s $DeviceId shell am force-stop $pkg | Out-Null
|
& adb -s $DeviceId shell am force-stop $pkg | Out-Null
|
||||||
$deadline = (Get-Date).AddSeconds(6)
|
$deadline = (Get-Date).AddSeconds(10)
|
||||||
while ((& adb -s $DeviceId shell pidof $pkg) -and (Get-Date) -lt $deadline) {
|
while ((& adb -s $DeviceId shell pidof $pkg) -and (Get-Date) -lt $deadline) {
|
||||||
Start-Sleep -Milliseconds 300
|
Start-Sleep -Milliseconds 300
|
||||||
}
|
}
|
||||||
|
# 进程还在说明被系统冻结/保活,直接等到超时也无意义,先给它一点时间解冻
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
& adb -s $DeviceId logcat -c
|
& adb -s $DeviceId logcat -c
|
||||||
# 用 MAIN/LAUNCHER 意图启动:applicationId 带 .dev 后缀时,
|
|
||||||
# "am start -n $pkg/.MainActivity" 会把 .MainActivity 拼到 .dev 上,导致找不到类。
|
|
||||||
# 解析真正的启动组件再启动:applicationId 带 .dev 后缀时,
|
# 解析真正的启动组件再启动:applicationId 带 .dev 后缀时,
|
||||||
# "$pkg/.MainActivity" 会把 .MainActivity 拼到 .dev 上导致找不到类;
|
# "$pkg/.MainActivity" 会把 .MainActivity 拼到 .dev 上导致找不到类;
|
||||||
# 而 "am start -p $pkg" 在部分 ROM 上又解析不到,所以直接问 PackageManager。
|
# 而 "am start -p $pkg" 在部分 ROM 上又解析不到,所以直接问 PackageManager。
|
||||||
$component = (& adb -s $DeviceId shell cmd package resolve-activity --brief $pkg 2>&1 | Select-Object -Last 1).Trim()
|
$component = (& adb -s $DeviceId shell cmd package resolve-activity --brief $pkg 2>&1 | Select-Object -Last 1).Trim()
|
||||||
& adb -s $DeviceId shell am start -W -n $component 2>&1 | Out-Null
|
& adb -s $DeviceId shell am start -W -n $component 2>&1 | Out-Null
|
||||||
Start-Sleep -Seconds $WaitSeconds
|
# 第一次按参数等待;第二次重试时多等一会儿(Flyme 解冻可能很慢)
|
||||||
|
$waitThisTime = if ($attempt -eq 1) { $WaitSeconds } else { [Math]::Max($WaitSeconds, 20) }
|
||||||
|
Start-Sleep -Seconds $waitThisTime
|
||||||
& adb -s $DeviceId logcat -d -v time > $logPath
|
& adb -s $DeviceId logcat -d -v time > $logPath
|
||||||
# 注意:PS 5.1 的 > 重定向写出的是 UTF-16LE(带 BOM),读取时不要强制 utf8
|
# 注意:PS 5.1 的 > 重定向写出的是 UTF-16LE(带 BOM),读取时不要强制 utf8
|
||||||
$log = Get-Content $logPath
|
$log = Get-Content $logPath
|
||||||
|
|||||||
Reference in New Issue
Block a user