Skip to content

Commit f32f86a

Browse files
committed
fix: use more accurate PID detection on restart for android
1 parent a64f25b commit f32f86a

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

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

+21-12
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?.();
@@ -195,14 +194,16 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
195194
];
196195

197196
if (pid && isLogcatPidSupported) {
198-
logcatCommand.push(`--pid=${pid}`);
197+
// logcatCommand.push(`--pid=${pid}`);
199198

200199
acceptedTags.forEach((tag) => {
201200
// -s <tag> - shows only logs with the specified tag
202-
logcatCommand.push("-s", tag);
201+
// logcatCommand.push("-s", tag);
203202
});
204203
}
205204

205+
console.log("-------------LOGCAT COMMAND", logcatCommand);
206+
206207
const logcatStream = await adb.executeCommand(logcatCommand, {
207208
returnChildProcess: true,
208209
});
@@ -221,7 +222,15 @@ export class LogcatHelper implements Mobile.ILogcatHelper {
221222

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

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

0 commit comments

Comments
 (0)