Skip to content

Commit 6509773

Browse files
authored
fix(android): use more accurate PID detection on restart (#5804)
1 parent 62ffa30 commit 6509773

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

lib/common/mobile/android/logcat-helper.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,16 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
9393
return;
9494
const lines = (lineBuffer.toString() || "").split("\n");
9595
for (let line of lines) {
96-
// 09-11 17:50:26.311 598 1979 I ActivityTaskManager: START u0 {flg=0x10000000 cmp=org.nativescript.myApp/com.tns.NativeScriptActivity} from uid 2000
97-
// ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^^
98-
// action appId pid
96+
// 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}
97+
98+
const startProc = /Start proc (?<pid>[0-9]+):(?<appId>.+?)\//.exec(
99+
line
100+
);
99101

100102
if (
101-
// action
102-
line.includes("START") &&
103-
// appId
104-
line.includes(options.appId) &&
105-
// pid - only if it's not the current pid...
106-
!line.includes(options.pid)
103+
startProc &&
104+
startProc.groups?.appId === options.appId &&
105+
startProc.groups?.pid !== options.pid
107106
) {
108107
this.forceStop(deviceIdentifier);
109108
options.onAppRestarted?.();
@@ -221,7 +220,15 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
221220

222221
// -b system - shows the system buffer/logs only
223222
// -T 1 - shows only new logs after starting adb logcat
224-
const logcatCommand = [`logcat`, `-b`, `system`, `-T`, `1`];
223+
const logcatCommand = [
224+
`logcat`,
225+
`-b`,
226+
`system`,
227+
`-T`,
228+
`1`,
229+
"-s",
230+
"ActivityManager",
231+
];
225232

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

0 commit comments

Comments
 (0)