Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use more accurate PID detection on restart for android #5804

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions lib/common/mobile/android/logcat-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,16 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
return;
const lines = (lineBuffer.toString() || "").split("\n");
for (let line of lines) {
// 09-11 17:50:26.311 598 1979 I ActivityTaskManager: START u0 {flg=0x10000000 cmp=org.nativescript.myApp/com.tns.NativeScriptActivity} from uid 2000
// ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^
// action appId pid
// 2024-06-26 16:43:22.286 630-659 ActivityManager system_server I Start proc 8854:org.nativescript.uitestsapp/u0a190 for next-top-activity {org.nativescript.uitestsapp/com.tns.NativeScriptActivity}

const startProc = /Start proc (?<pid>[0-9]+):(?<appId>.+?)\//.exec(
line
);

if (
// action
line.includes("START") &&
// appId
line.includes(options.appId) &&
// pid - only if it's not the current pid...
!line.includes(options.pid)
startProc &&
startProc.groups?.appId === options.appId &&
startProc.groups?.pid !== options.pid
) {
this.forceStop(deviceIdentifier);
options.onAppRestarted?.();
Expand Down Expand Up @@ -221,7 +220,15 @@ export class LogcatHelper implements Mobile.ILogcatHelper {

// -b system - shows the system buffer/logs only
// -T 1 - shows only new logs after starting adb logcat
const logcatCommand = [`logcat`, `-b`, `system`, `-T`, `1`];
const logcatCommand = [
`logcat`,
`-b`,
`system`,
`-T`,
`1`,
"-s",
"ActivityManager",
];

if (appId) {
logcatCommand.push(`--regex=START.*${appId}`);
Expand Down