@react-native-harness/platform-android 1.0.0 → 1.1.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/adb.test.d.ts +2 -0
- package/dist/__tests__/adb.test.d.ts.map +1 -0
- package/dist/__tests__/adb.test.js +72 -0
- package/dist/__tests__/app-monitor.test.d.ts +2 -0
- package/dist/__tests__/app-monitor.test.d.ts.map +1 -0
- package/dist/__tests__/app-monitor.test.js +202 -0
- package/dist/__tests__/crash-parser.test.d.ts +2 -0
- package/dist/__tests__/crash-parser.test.d.ts.map +1 -0
- package/dist/__tests__/crash-parser.test.js +45 -0
- package/dist/__tests__/shared-prefs.test.d.ts +2 -0
- package/dist/__tests__/shared-prefs.test.d.ts.map +1 -0
- package/dist/__tests__/shared-prefs.test.js +87 -0
- package/dist/adb.d.ts +6 -1
- package/dist/adb.d.ts.map +1 -1
- package/dist/adb.js +84 -18
- package/dist/app-monitor.d.ts +13 -0
- package/dist/app-monitor.d.ts.map +1 -0
- package/dist/app-monitor.js +359 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -0
- package/dist/crash-parser.d.ts +11 -0
- package/dist/crash-parser.d.ts.map +1 -0
- package/dist/crash-parser.js +39 -0
- package/dist/runner.d.ts +2 -2
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +21 -5
- package/dist/shared-prefs.d.ts +3 -0
- package/dist/shared-prefs.d.ts.map +1 -0
- package/dist/shared-prefs.js +92 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/eslint.config.mjs +4 -1
- package/package.json +4 -4
- package/src/__tests__/adb.test.ts +89 -0
- package/src/__tests__/app-monitor.test.ts +273 -0
- package/src/__tests__/crash-parser.test.ts +52 -0
- package/src/__tests__/shared-prefs.test.ts +144 -0
- package/src/adb.ts +111 -18
- package/src/app-monitor.ts +544 -0
- package/src/config.ts +10 -0
- package/src/crash-parser.ts +66 -0
- package/src/runner.ts +31 -7
- package/src/shared-prefs.ts +205 -0
- package/tsconfig.json +2 -2
- package/tsconfig.lib.json +2 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/assertions.d.ts +0 -5
- package/dist/assertions.d.ts.map +0 -1
- package/dist/assertions.js +0 -6
- package/dist/emulator.d.ts +0 -6
- package/dist/emulator.d.ts.map +0 -1
- package/dist/emulator.js +0 -27
- package/dist/errors.d.ts +0 -15
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -28
- package/dist/reader.d.ts +0 -6
- package/dist/reader.d.ts.map +0 -1
- package/dist/reader.js +0 -57
- package/dist/types.d.ts +0 -381
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -107
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { escapeRegExp, getEmitter, logger, spawn, SubprocessError } from '@react-native-harness/tools';
|
|
2
|
+
import * as adb from './adb.js';
|
|
3
|
+
import { androidCrashParser } from './crash-parser.js';
|
|
4
|
+
const androidAppMonitorLogger = logger.child('android-app-monitor');
|
|
5
|
+
const getLogcatArgs = (uid, fromTime) => ['logcat', '-v', 'threadtime', '-b', 'crash', `--uid=${uid}`, '-T', fromTime];
|
|
6
|
+
const MAX_RECENT_LOG_LINES = 200;
|
|
7
|
+
const MAX_RECENT_CRASH_ARTIFACTS = 10;
|
|
8
|
+
const CRASH_ARTIFACT_SETTLE_DELAY_MS = 100;
|
|
9
|
+
const startProcPattern = (bundleId) => new RegExp(`Start proc (\\d+):${escapeRegExp(bundleId)}(?:/|\\s)`);
|
|
10
|
+
const processPattern = (bundleId) => new RegExp(`Process:\\s*${escapeRegExp(bundleId)},\\s*PID:\\s*(\\d+)`);
|
|
11
|
+
const nativeCrashPattern = (bundleId) => new RegExp(`>>>\\s*${escapeRegExp(bundleId)}\\s*<<<`);
|
|
12
|
+
const processDiedPattern = (bundleId) => new RegExp(`Process\\s+${escapeRegExp(bundleId)}\\s+\\(pid\\s+(\\d+)\\)\\s+has\\s+died`, 'i');
|
|
13
|
+
const getSignal = (line) => {
|
|
14
|
+
const namedSignalMatch = line.match(/\b(SIG[A-Z0-9]+)\b/);
|
|
15
|
+
if (namedSignalMatch) {
|
|
16
|
+
return namedSignalMatch[1];
|
|
17
|
+
}
|
|
18
|
+
const signalNumberMatch = line.match(/signal\s+(\d+)/i);
|
|
19
|
+
if (signalNumberMatch) {
|
|
20
|
+
return `signal ${signalNumberMatch[1]}`;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
};
|
|
24
|
+
const getAndroidLogLineCrashDetails = ({ line, bundleId, pid, }) => {
|
|
25
|
+
const fatalExceptionMatch = line.match(/FATAL EXCEPTION:\s*(.+)$/i);
|
|
26
|
+
const processMatch = line.match(processPattern(bundleId));
|
|
27
|
+
return {
|
|
28
|
+
source: 'logs',
|
|
29
|
+
summary: line.trim(),
|
|
30
|
+
signal: getSignal(line),
|
|
31
|
+
exceptionType: fatalExceptionMatch?.[1]?.trim(),
|
|
32
|
+
processName: processMatch ? bundleId : line.includes(bundleId) ? bundleId : undefined,
|
|
33
|
+
pid: pid ?? (processMatch ? Number(processMatch[1]) : undefined),
|
|
34
|
+
rawLines: [line],
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const CRASH_BLOCK_HEADER = '--------- beginning of crash';
|
|
38
|
+
const getLatestCrashBlock = (recentLogLines) => {
|
|
39
|
+
const lines = recentLogLines.map(({ line }) => line);
|
|
40
|
+
let latestCrashHeaderIndex = -1;
|
|
41
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
42
|
+
if (/FATAL EXCEPTION:|Process:\s+.+,\s+PID:/i.test(lines[index])) {
|
|
43
|
+
latestCrashHeaderIndex = index;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const blockStartIndex = Math.max(lines.lastIndexOf(CRASH_BLOCK_HEADER), latestCrashHeaderIndex);
|
|
48
|
+
if (blockStartIndex === -1) {
|
|
49
|
+
return lines;
|
|
50
|
+
}
|
|
51
|
+
return lines.slice(blockStartIndex);
|
|
52
|
+
};
|
|
53
|
+
const getCrashBlockForArtifact = ({ artifact, recentLogLines, }) => {
|
|
54
|
+
const targetIndex = recentLogLines.findIndex(({ line, occurredAt }) => line === artifact.triggerLine &&
|
|
55
|
+
(artifact.triggerOccurredAt === undefined ||
|
|
56
|
+
occurredAt === artifact.triggerOccurredAt));
|
|
57
|
+
if (targetIndex === -1) {
|
|
58
|
+
return artifact.rawLines ?? [];
|
|
59
|
+
}
|
|
60
|
+
let blockStartIndex = targetIndex;
|
|
61
|
+
for (let index = targetIndex; index >= 0; index -= 1) {
|
|
62
|
+
const { line } = recentLogLines[index];
|
|
63
|
+
if (line === CRASH_BLOCK_HEADER) {
|
|
64
|
+
blockStartIndex = index;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let blockEndIndex = recentLogLines.length;
|
|
69
|
+
for (let index = targetIndex + 1; index < recentLogLines.length; index += 1) {
|
|
70
|
+
if (recentLogLines[index].line === CRASH_BLOCK_HEADER) {
|
|
71
|
+
blockEndIndex = index;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return recentLogLines
|
|
76
|
+
.slice(blockStartIndex, blockEndIndex)
|
|
77
|
+
.map(({ line }) => line);
|
|
78
|
+
};
|
|
79
|
+
const hydrateCrashArtifact = ({ artifact, recentLogLines, }) => {
|
|
80
|
+
const rawLines = getCrashBlockForArtifact({ artifact, recentLogLines });
|
|
81
|
+
if (rawLines.length === 0) {
|
|
82
|
+
return artifact;
|
|
83
|
+
}
|
|
84
|
+
const parsedDetails = androidCrashParser.parse({
|
|
85
|
+
contents: rawLines.join('\n'),
|
|
86
|
+
bundleId: artifact.processName ?? '',
|
|
87
|
+
pid: artifact.pid,
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
...artifact,
|
|
91
|
+
...parsedDetails,
|
|
92
|
+
artifactType: artifact.artifactType,
|
|
93
|
+
artifactPath: artifact.artifactPath,
|
|
94
|
+
rawLines,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const createCrashArtifact = ({ details, recentLogLines, }) => {
|
|
98
|
+
const occurredAt = Date.now();
|
|
99
|
+
const rawLines = getLatestCrashBlock(recentLogLines);
|
|
100
|
+
const triggerOccurredAt = [...recentLogLines]
|
|
101
|
+
.reverse()
|
|
102
|
+
.find(({ line }) => line === details.summary)?.occurredAt;
|
|
103
|
+
const contents = rawLines.length > 0
|
|
104
|
+
? rawLines.join('\n')
|
|
105
|
+
: (details.rawLines ?? []).join('\n');
|
|
106
|
+
const parsedDetails = details.processName !== undefined
|
|
107
|
+
? androidCrashParser.parse({
|
|
108
|
+
contents,
|
|
109
|
+
bundleId: details.processName,
|
|
110
|
+
pid: details.pid,
|
|
111
|
+
})
|
|
112
|
+
: details;
|
|
113
|
+
return {
|
|
114
|
+
...parsedDetails,
|
|
115
|
+
occurredAt,
|
|
116
|
+
triggerLine: details.summary ?? '',
|
|
117
|
+
triggerOccurredAt,
|
|
118
|
+
artifactType: 'logcat',
|
|
119
|
+
rawLines: rawLines.length > 0 ? rawLines : parsedDetails.rawLines ?? details.rawLines,
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
const persistCrashArtifact = ({ details, crashArtifactWriter, }) => {
|
|
123
|
+
if (!crashArtifactWriter || details.artifactType !== 'logcat') {
|
|
124
|
+
return details;
|
|
125
|
+
}
|
|
126
|
+
const artifactBody = details.rawLines?.join('\n');
|
|
127
|
+
if (!artifactBody) {
|
|
128
|
+
return details;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
...details,
|
|
132
|
+
artifactPath: crashArtifactWriter.persistArtifact({
|
|
133
|
+
artifactKind: details.artifactType,
|
|
134
|
+
source: {
|
|
135
|
+
kind: 'text',
|
|
136
|
+
fileName: 'logcat.txt',
|
|
137
|
+
text: `${artifactBody}\n`,
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
const getLatestCrashArtifact = ({ crashArtifacts, recentLogLines, processName, pid, occurredAt, }) => {
|
|
143
|
+
const matchingByPid = pid
|
|
144
|
+
? crashArtifacts.filter((artifact) => artifact.pid === pid)
|
|
145
|
+
: [];
|
|
146
|
+
const matchingByProcess = processName
|
|
147
|
+
? crashArtifacts.filter((artifact) => artifact.processName === processName)
|
|
148
|
+
: [];
|
|
149
|
+
const candidates = matchingByPid.length > 0
|
|
150
|
+
? matchingByPid
|
|
151
|
+
: matchingByProcess.length > 0
|
|
152
|
+
? matchingByProcess
|
|
153
|
+
: crashArtifacts;
|
|
154
|
+
const sortedCandidates = [...candidates].sort((left, right) => Math.abs(left.occurredAt - occurredAt) - Math.abs(right.occurredAt - occurredAt));
|
|
155
|
+
const artifact = sortedCandidates[0];
|
|
156
|
+
if (!artifact) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return hydrateCrashArtifact({
|
|
160
|
+
artifact,
|
|
161
|
+
recentLogLines,
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
const createAndroidLogEvent = (line, bundleId) => {
|
|
165
|
+
const startMatch = line.match(startProcPattern(bundleId));
|
|
166
|
+
if (startMatch) {
|
|
167
|
+
return {
|
|
168
|
+
type: 'app_started',
|
|
169
|
+
pid: Number(startMatch[1]),
|
|
170
|
+
source: 'logs',
|
|
171
|
+
line,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const processMatch = line.match(processPattern(bundleId));
|
|
175
|
+
if (processMatch) {
|
|
176
|
+
return {
|
|
177
|
+
type: 'possible_crash',
|
|
178
|
+
pid: Number(processMatch[1]),
|
|
179
|
+
source: 'logs',
|
|
180
|
+
line,
|
|
181
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
182
|
+
line,
|
|
183
|
+
bundleId,
|
|
184
|
+
pid: Number(processMatch[1]),
|
|
185
|
+
}),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (nativeCrashPattern(bundleId).test(line)) {
|
|
189
|
+
return {
|
|
190
|
+
type: 'possible_crash',
|
|
191
|
+
source: 'logs',
|
|
192
|
+
line,
|
|
193
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
194
|
+
line,
|
|
195
|
+
bundleId,
|
|
196
|
+
}),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const diedMatch = line.match(processDiedPattern(bundleId));
|
|
200
|
+
if (diedMatch) {
|
|
201
|
+
return {
|
|
202
|
+
type: 'app_exited',
|
|
203
|
+
pid: Number(diedMatch[1]),
|
|
204
|
+
source: 'logs',
|
|
205
|
+
line,
|
|
206
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
207
|
+
line,
|
|
208
|
+
bundleId,
|
|
209
|
+
pid: Number(diedMatch[1]),
|
|
210
|
+
}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (line.includes(bundleId) &&
|
|
214
|
+
/fatal|crash|signal 11|signal 6|backtrace/i.test(line)) {
|
|
215
|
+
return {
|
|
216
|
+
type: 'possible_crash',
|
|
217
|
+
source: 'logs',
|
|
218
|
+
line,
|
|
219
|
+
crashDetails: getAndroidLogLineCrashDetails({
|
|
220
|
+
line,
|
|
221
|
+
bundleId,
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
};
|
|
227
|
+
export const createAndroidAppMonitor = ({ adbId, bundleId, appUid, crashArtifactWriter, }) => {
|
|
228
|
+
const emitter = getEmitter();
|
|
229
|
+
let isStarted = false;
|
|
230
|
+
let logcatProcess = null;
|
|
231
|
+
let logTask = null;
|
|
232
|
+
let recentLogLines = [];
|
|
233
|
+
let recentCrashArtifacts = [];
|
|
234
|
+
const emit = (event) => {
|
|
235
|
+
emitter.emit(event);
|
|
236
|
+
};
|
|
237
|
+
const recordLogLine = (line) => {
|
|
238
|
+
recentLogLines = [...recentLogLines, { line, occurredAt: Date.now() }].slice(-MAX_RECENT_LOG_LINES);
|
|
239
|
+
};
|
|
240
|
+
const recordCrashArtifact = (details) => {
|
|
241
|
+
if (!details) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
recentCrashArtifacts = [
|
|
245
|
+
...recentCrashArtifacts,
|
|
246
|
+
createCrashArtifact({
|
|
247
|
+
details,
|
|
248
|
+
recentLogLines,
|
|
249
|
+
}),
|
|
250
|
+
].slice(-MAX_RECENT_CRASH_ARTIFACTS);
|
|
251
|
+
};
|
|
252
|
+
const stopProcess = async (child) => {
|
|
253
|
+
if (!child) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
(await child.nodeChildProcess).kill();
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
// Ignore termination failures for background monitors.
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
const startLogcat = async () => {
|
|
264
|
+
const logcatTimestamp = await adb.getLogcatTimestamp(adbId);
|
|
265
|
+
logcatProcess = spawn('adb', ['-s', adbId, ...getLogcatArgs(appUid, logcatTimestamp)], {
|
|
266
|
+
stdout: 'pipe',
|
|
267
|
+
stderr: 'pipe',
|
|
268
|
+
});
|
|
269
|
+
const currentProcess = logcatProcess;
|
|
270
|
+
if (!currentProcess) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
logTask = (async () => {
|
|
274
|
+
try {
|
|
275
|
+
for await (const line of currentProcess) {
|
|
276
|
+
recordLogLine(line);
|
|
277
|
+
emit({ type: 'log', source: 'logs', line });
|
|
278
|
+
const event = createAndroidLogEvent(line, bundleId);
|
|
279
|
+
if (event) {
|
|
280
|
+
if (event.type === 'possible_crash' || event.type === 'app_exited') {
|
|
281
|
+
recordCrashArtifact(event.crashDetails);
|
|
282
|
+
}
|
|
283
|
+
emit(event);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (!(error instanceof SubprocessError && error.signalName === 'SIGTERM')) {
|
|
289
|
+
androidAppMonitorLogger.debug('Android logcat monitor stopped', error);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
})();
|
|
293
|
+
};
|
|
294
|
+
const start = async () => {
|
|
295
|
+
if (isStarted) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
await startLogcat();
|
|
300
|
+
isStarted = true;
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
const currentProcess = logcatProcess;
|
|
304
|
+
const currentTask = logTask;
|
|
305
|
+
logcatProcess = null;
|
|
306
|
+
logTask = null;
|
|
307
|
+
await stopProcess(currentProcess);
|
|
308
|
+
await currentTask;
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const stop = async () => {
|
|
313
|
+
if (!isStarted) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
isStarted = false;
|
|
317
|
+
const currentProcess = logcatProcess;
|
|
318
|
+
const currentTask = logTask;
|
|
319
|
+
logcatProcess = null;
|
|
320
|
+
logTask = null;
|
|
321
|
+
await stopProcess(currentProcess);
|
|
322
|
+
await currentTask;
|
|
323
|
+
};
|
|
324
|
+
const dispose = async () => {
|
|
325
|
+
await stop();
|
|
326
|
+
emitter.clearAllListeners();
|
|
327
|
+
recentLogLines = [];
|
|
328
|
+
recentCrashArtifacts = [];
|
|
329
|
+
};
|
|
330
|
+
const addListener = (listener) => {
|
|
331
|
+
emitter.addListener(listener);
|
|
332
|
+
};
|
|
333
|
+
const removeListener = (listener) => {
|
|
334
|
+
emitter.removeListener(listener);
|
|
335
|
+
};
|
|
336
|
+
return {
|
|
337
|
+
start,
|
|
338
|
+
stop,
|
|
339
|
+
dispose,
|
|
340
|
+
addListener,
|
|
341
|
+
removeListener,
|
|
342
|
+
getCrashDetails: async (options) => {
|
|
343
|
+
await new Promise((resolve) => setTimeout(resolve, CRASH_ARTIFACT_SETTLE_DELAY_MS));
|
|
344
|
+
const details = getLatestCrashArtifact({
|
|
345
|
+
crashArtifacts: recentCrashArtifacts,
|
|
346
|
+
recentLogLines,
|
|
347
|
+
...options,
|
|
348
|
+
});
|
|
349
|
+
if (!details) {
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
return persistCrashArtifact({
|
|
353
|
+
details,
|
|
354
|
+
crashArtifactWriter,
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
export { createAndroidLogEvent };
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export declare const AndroidAppLaunchOptionsSchema: z.ZodObject<{
|
|
3
|
+
extras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber]>>>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
8
|
+
}>;
|
|
2
9
|
export declare const AndroidEmulatorAVDConfigSchema: z.ZodObject<{
|
|
3
10
|
apiLevel: z.ZodNumber;
|
|
4
11
|
profile: z.ZodString;
|
|
@@ -170,6 +177,13 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
170
177
|
}>]>;
|
|
171
178
|
bundleId: z.ZodString;
|
|
172
179
|
activityName: z.ZodDefault<z.ZodString>;
|
|
180
|
+
appLaunchOptions: z.ZodOptional<z.ZodObject<{
|
|
181
|
+
extras: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodBoolean, z.ZodNumber]>>>;
|
|
182
|
+
}, "strip", z.ZodTypeAny, {
|
|
183
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
186
|
+
}>>;
|
|
173
187
|
}, "strip", z.ZodTypeAny, {
|
|
174
188
|
name: string;
|
|
175
189
|
device: {
|
|
@@ -188,6 +202,9 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
188
202
|
};
|
|
189
203
|
bundleId: string;
|
|
190
204
|
activityName: string;
|
|
205
|
+
appLaunchOptions?: {
|
|
206
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
207
|
+
} | undefined;
|
|
191
208
|
}, {
|
|
192
209
|
name: string;
|
|
193
210
|
device: {
|
|
@@ -206,11 +223,15 @@ export declare const AndroidPlatformConfigSchema: z.ZodObject<{
|
|
|
206
223
|
};
|
|
207
224
|
bundleId: string;
|
|
208
225
|
activityName?: string | undefined;
|
|
226
|
+
appLaunchOptions?: {
|
|
227
|
+
extras?: Record<string, string | number | boolean> | undefined;
|
|
228
|
+
} | undefined;
|
|
209
229
|
}>;
|
|
210
230
|
export type AndroidEmulator = z.infer<typeof AndroidEmulatorSchema>;
|
|
211
231
|
export type PhysicalAndroidDevice = z.infer<typeof PhysicalAndroidDeviceSchema>;
|
|
212
232
|
export type AndroidDevice = z.infer<typeof AndroidDeviceSchema>;
|
|
213
233
|
export type AndroidPlatformConfig = z.infer<typeof AndroidPlatformConfigSchema>;
|
|
234
|
+
export type AndroidAppLaunchOptions = z.infer<typeof AndroidAppLaunchOptionsSchema>;
|
|
214
235
|
export type AndroidEmulatorAVDConfig = z.infer<typeof AndroidEmulatorAVDConfigSchema>;
|
|
215
236
|
export declare const isAndroidDeviceEmulator: (device: AndroidDevice) => device is AndroidEmulator;
|
|
216
237
|
export declare const isAndroidDevicePhysical: (device: AndroidDevice) => device is PhysicalAndroidDevice;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;EAKzC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIhC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG9B,CAAC;AAEH,eAAO,MAAM,2BAA2B
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,6BAA6B;;;;;;EAIxC,CAAC;AAEH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;EAKzC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIhC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;EAItC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAG9B,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAStC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAChF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAC5C,OAAO,8BAA8B,CACtC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,QAAQ,aAAa,KACpB,MAAM,IAAI,eAEZ,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,QAAQ,aAAa,KACpB,MAAM,IAAI,qBAEZ,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,IAAI,eAAe,CAInC;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,IAAI,qBAAqB,CAIzC"}
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export const AndroidAppLaunchOptionsSchema = z.object({
|
|
3
|
+
extras: z
|
|
4
|
+
.record(z.union([z.string(), z.boolean(), z.number().int().safe()]))
|
|
5
|
+
.optional(),
|
|
6
|
+
});
|
|
2
7
|
export const AndroidEmulatorAVDConfigSchema = z.object({
|
|
3
8
|
apiLevel: z.number().min(1, 'API level is required'),
|
|
4
9
|
profile: z.string().min(1, 'Profile is required'),
|
|
@@ -27,6 +32,7 @@ export const AndroidPlatformConfigSchema = z.object({
|
|
|
27
32
|
.string()
|
|
28
33
|
.min(1, 'Activity name is required')
|
|
29
34
|
.default('.MainActivity'),
|
|
35
|
+
appLaunchOptions: AndroidAppLaunchOptionsSchema.optional(),
|
|
30
36
|
});
|
|
31
37
|
export const isAndroidDeviceEmulator = (device) => {
|
|
32
38
|
return device.type === 'emulator';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AppCrashDetails } from '@react-native-harness/platforms';
|
|
2
|
+
type ParseAndroidCrashReportOptions = {
|
|
3
|
+
contents: string;
|
|
4
|
+
bundleId: string;
|
|
5
|
+
pid?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const androidCrashParser: {
|
|
8
|
+
parse({ contents, bundleId, pid, }: ParseAndroidCrashReportOptions): AppCrashDetails;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=crash-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crash-parser.d.ts","sourceRoot":"","sources":["../src/crash-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE,KAAK,8BAA8B,GAAG;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AA4BF,eAAO,MAAM,kBAAkB;wCAK1B,8BAA8B,GAAG,eAAe;CAyBpD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { escapeRegExp } from '@react-native-harness/tools';
|
|
2
|
+
const getSignal = (contents) => {
|
|
3
|
+
const namedSignalMatch = contents.match(/\b(SIG[A-Z0-9]+)\b/);
|
|
4
|
+
if (namedSignalMatch) {
|
|
5
|
+
return namedSignalMatch[1];
|
|
6
|
+
}
|
|
7
|
+
const signalNumberMatch = contents.match(/signal\s+(\d+)/i);
|
|
8
|
+
if (signalNumberMatch) {
|
|
9
|
+
return `signal ${signalNumberMatch[1]}`;
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
};
|
|
13
|
+
const getStackTrace = (rawLines) => {
|
|
14
|
+
const frames = rawLines.filter((line) => /^\S.*(?:\s+at\s+|\s+#\d+\s+pc\s+)/.test(line.trim()) ||
|
|
15
|
+
/^\S.*AndroidRuntime:\s+at\s+/.test(line.trim()) ||
|
|
16
|
+
/^\S.*AndroidRuntime:\s+Caused by:/.test(line.trim()));
|
|
17
|
+
return frames.length > 0 ? frames : undefined;
|
|
18
|
+
};
|
|
19
|
+
export const androidCrashParser = {
|
|
20
|
+
parse({ contents, bundleId, pid, }) {
|
|
21
|
+
const rawLines = contents.split(/\r?\n/);
|
|
22
|
+
const processPattern = new RegExp(`Process:\\s*${escapeRegExp(bundleId)},\\s*PID:\\s*(\\d+)`);
|
|
23
|
+
const fatalExceptionMatch = contents.match(/FATAL EXCEPTION:\s*(.+)$/im);
|
|
24
|
+
const processMatch = contents.match(processPattern);
|
|
25
|
+
const runtimeExceptionLine = rawLines.find((line) => /AndroidRuntime: (?:java\.|kotlin\.|[\w$.]+(?:Exception|Error):)/.test(line));
|
|
26
|
+
const exceptionType = fatalExceptionMatch?.[1]?.trim() ??
|
|
27
|
+
runtimeExceptionLine?.match(/AndroidRuntime:\s+(.+)$/)?.[1]?.trim();
|
|
28
|
+
return {
|
|
29
|
+
source: 'logs',
|
|
30
|
+
summary: contents.trim(),
|
|
31
|
+
signal: getSignal(contents),
|
|
32
|
+
exceptionType,
|
|
33
|
+
processName: processMatch ? bundleId : contents.includes(bundleId) ? bundleId : undefined,
|
|
34
|
+
pid: pid ?? (processMatch ? Number(processMatch[1]) : undefined),
|
|
35
|
+
rawLines,
|
|
36
|
+
stackTrace: getStackTrace(rawLines),
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
};
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HarnessPlatformRunner } from '@react-native-harness/platforms';
|
|
2
|
-
import { Config } from '@react-native-harness/config';
|
|
2
|
+
import type { Config as HarnessConfig } from '@react-native-harness/config';
|
|
3
3
|
import { type AndroidPlatformConfig } from './config.js';
|
|
4
|
-
declare const getAndroidRunner: (config: AndroidPlatformConfig, harnessConfig:
|
|
4
|
+
declare const getAndroidRunner: (config: AndroidPlatformConfig, harnessConfig: HarnessConfig) => Promise<HarnessPlatformRunner>;
|
|
5
5
|
export default getAndroidRunner;
|
|
6
6
|
//# sourceMappingURL=runner.d.ts.map
|
package/dist/runner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../src/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,aAAa,CAAC;AAUrB,QAAA,MAAM,gBAAgB,GACpB,QAAQ,qBAAqB,EAC7B,eAAe,aAAa,KAC3B,OAAO,CAAC,qBAAqB,CAmE/B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/runner.js
CHANGED
|
@@ -2,7 +2,9 @@ import { DeviceNotFoundError, AppNotInstalledError, } from '@react-native-harnes
|
|
|
2
2
|
import { AndroidPlatformConfigSchema, } from './config.js';
|
|
3
3
|
import { getAdbId } from './adb-id.js';
|
|
4
4
|
import * as adb from './adb.js';
|
|
5
|
+
import { applyHarnessDebugHttpHost, clearHarnessDebugHttpHost, } from './shared-prefs.js';
|
|
5
6
|
import { getDeviceName } from './utils.js';
|
|
7
|
+
import { createAndroidAppMonitor } from './app-monitor.js';
|
|
6
8
|
const getAndroidRunner = async (config, harnessConfig) => {
|
|
7
9
|
const parsedConfig = AndroidPlatformConfigSchema.parse(config);
|
|
8
10
|
const adbId = await getAdbId(parsedConfig.device);
|
|
@@ -13,28 +15,42 @@ const getAndroidRunner = async (config, harnessConfig) => {
|
|
|
13
15
|
if (!isInstalled) {
|
|
14
16
|
throw new AppNotInstalledError(parsedConfig.bundleId, getDeviceName(parsedConfig.device));
|
|
15
17
|
}
|
|
18
|
+
const metroPort = harnessConfig.metroPort;
|
|
16
19
|
await Promise.all([
|
|
17
|
-
adb.reversePort(adbId,
|
|
20
|
+
adb.reversePort(adbId, metroPort),
|
|
18
21
|
adb.reversePort(adbId, 8080),
|
|
19
22
|
adb.reversePort(adbId, harnessConfig.webSocketPort),
|
|
23
|
+
adb.setHideErrorDialogs(adbId, true),
|
|
24
|
+
applyHarnessDebugHttpHost(adbId, parsedConfig.bundleId, `localhost:${metroPort}`),
|
|
20
25
|
]);
|
|
26
|
+
const appUid = await adb.getAppUid(adbId, parsedConfig.bundleId);
|
|
21
27
|
return {
|
|
22
|
-
startApp: async () => {
|
|
23
|
-
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName
|
|
28
|
+
startApp: async (options) => {
|
|
29
|
+
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName, options ??
|
|
30
|
+
parsedConfig.appLaunchOptions);
|
|
24
31
|
},
|
|
25
|
-
restartApp: async () => {
|
|
32
|
+
restartApp: async (options) => {
|
|
26
33
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
27
|
-
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName
|
|
34
|
+
await adb.startApp(adbId, parsedConfig.bundleId, parsedConfig.activityName, options ??
|
|
35
|
+
parsedConfig.appLaunchOptions);
|
|
28
36
|
},
|
|
29
37
|
stopApp: async () => {
|
|
30
38
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
31
39
|
},
|
|
32
40
|
dispose: async () => {
|
|
33
41
|
await adb.stopApp(adbId, parsedConfig.bundleId);
|
|
42
|
+
await clearHarnessDebugHttpHost(adbId, parsedConfig.bundleId);
|
|
43
|
+
await adb.setHideErrorDialogs(adbId, false);
|
|
34
44
|
},
|
|
35
45
|
isAppRunning: async () => {
|
|
36
46
|
return await adb.isAppRunning(adbId, parsedConfig.bundleId);
|
|
37
47
|
},
|
|
48
|
+
createAppMonitor: (options) => createAndroidAppMonitor({
|
|
49
|
+
adbId,
|
|
50
|
+
bundleId: parsedConfig.bundleId,
|
|
51
|
+
appUid,
|
|
52
|
+
crashArtifactWriter: options?.crashArtifactWriter,
|
|
53
|
+
}),
|
|
38
54
|
};
|
|
39
55
|
};
|
|
40
56
|
export default getAndroidRunner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-prefs.d.ts","sourceRoot":"","sources":["../src/shared-prefs.ts"],"names":[],"mappings":"AAsJA,eAAO,MAAM,yBAAyB,GACpC,OAAO,MAAM,EACb,UAAU,MAAM,EAChB,MAAM,MAAM,KACX,OAAO,CAAC,IAAI,CAoBd,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,OAAO,MAAM,EACb,UAAU,MAAM,KACf,OAAO,CAAC,IAAI,CAyBd,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { spawn, SubprocessError } from '@react-native-harness/tools';
|
|
2
|
+
const DEBUG_HTTP_HOST_BLOCK_START = '<!-- react-native-harness:debug_http_host:start -->';
|
|
3
|
+
const DEBUG_HTTP_HOST_BLOCK_END = '<!-- react-native-harness:debug_http_host:end -->';
|
|
4
|
+
const DEBUG_HTTP_HOST_BACKUP_KEY = 'harness_debug_http_host_backup';
|
|
5
|
+
const getSharedPrefsPath = (bundleId) => `shared_prefs/${bundleId}_preferences.xml`;
|
|
6
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
7
|
+
const escapeXml = (value) => value
|
|
8
|
+
.replaceAll('&', '&')
|
|
9
|
+
.replaceAll('<', '<')
|
|
10
|
+
.replaceAll('>', '>')
|
|
11
|
+
.replaceAll('"', '"')
|
|
12
|
+
.replaceAll("'", ''');
|
|
13
|
+
const unescapeXml = (value) => value
|
|
14
|
+
.replaceAll(''', "'")
|
|
15
|
+
.replaceAll('"', '"')
|
|
16
|
+
.replaceAll('>', '>')
|
|
17
|
+
.replaceAll('<', '<')
|
|
18
|
+
.replaceAll('&', '&');
|
|
19
|
+
const getStringPreferenceRegex = (key) => new RegExp(`<string\\s+name="${escapeRegExp(key)}">([\\s\\S]*?)<\\/string>`, 'g');
|
|
20
|
+
const getStringPreferenceValue = (content, key) => {
|
|
21
|
+
const matches = [...content.matchAll(getStringPreferenceRegex(key))];
|
|
22
|
+
const value = matches.at(-1)?.[1];
|
|
23
|
+
return value == null ? null : unescapeXml(value);
|
|
24
|
+
};
|
|
25
|
+
const renameStringPreference = (content, fromKey, toKey) => content.replace(new RegExp(`(<string\\s+name=")${escapeRegExp(fromKey)}(">[\\s\\S]*?<\\/string>)`, 'g'), `$1${toKey}$2`);
|
|
26
|
+
const stripStringPreference = (content, key) => content.replace(new RegExp(`\\s*<string\\s+name="${escapeRegExp(key)}">[\\s\\S]*?<\\/string>\\s*`, 'g'), '\n');
|
|
27
|
+
const normalizeEmptyMap = (content) => content.replace(/<map\s*\/>/g, '<map>\n</map>');
|
|
28
|
+
const getHarnessDebugHttpHostBlock = (host) => [
|
|
29
|
+
DEBUG_HTTP_HOST_BLOCK_START,
|
|
30
|
+
`<string name="debug_http_host">${escapeXml(host)}</string>`,
|
|
31
|
+
DEBUG_HTTP_HOST_BLOCK_END,
|
|
32
|
+
].join('\n');
|
|
33
|
+
const stripHarnessDebugHttpHostBlock = (content) => content.replace(new RegExp(`\\s*${escapeRegExp(DEBUG_HTTP_HOST_BLOCK_START)}\\s*\\n[\\s\\S]*?\\n\\s*${escapeRegExp(DEBUG_HTTP_HOST_BLOCK_END)}\\s*`, 'g'), '\n');
|
|
34
|
+
const normalizeSharedPrefsContent = (content) => {
|
|
35
|
+
if (!content?.trim()) {
|
|
36
|
+
return ['<?xml version="1.0" encoding="utf-8"?>', '<map>', '</map>'].join('\n');
|
|
37
|
+
}
|
|
38
|
+
return normalizeEmptyMap(stripHarnessDebugHttpHostBlock(content)).trim();
|
|
39
|
+
};
|
|
40
|
+
const insertBeforeClosingMap = (content, block) => {
|
|
41
|
+
if (!content.includes('</map>')) {
|
|
42
|
+
throw new Error('Android shared preferences file is missing </map>.');
|
|
43
|
+
}
|
|
44
|
+
return content.replace(/<\/map>\s*$/, ` ${block.replace(/\n/g, '\n ')}\n</map>`);
|
|
45
|
+
};
|
|
46
|
+
const readSharedPrefsFile = async (adbId, bundleId) => {
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await spawn('adb', [
|
|
49
|
+
'-s',
|
|
50
|
+
adbId,
|
|
51
|
+
'shell',
|
|
52
|
+
`run-as ${bundleId} cat ${getSharedPrefsPath(bundleId)}`,
|
|
53
|
+
]);
|
|
54
|
+
return stdout;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof SubprocessError && error.exitCode === 1) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const writeSharedPrefsFile = async (adbId, bundleId, content) => {
|
|
64
|
+
await spawn('adb', [
|
|
65
|
+
'-s',
|
|
66
|
+
adbId,
|
|
67
|
+
'shell',
|
|
68
|
+
`run-as ${bundleId} sh -c 'mkdir -p shared_prefs && cat > ${getSharedPrefsPath(bundleId)}'`,
|
|
69
|
+
], { stdin: { string: `${content.trim()}\n` } });
|
|
70
|
+
};
|
|
71
|
+
export const applyHarnessDebugHttpHost = async (adbId, bundleId, host) => {
|
|
72
|
+
const existingContent = await readSharedPrefsFile(adbId, bundleId);
|
|
73
|
+
const normalizedContent = normalizeSharedPrefsContent(existingContent);
|
|
74
|
+
const existingHost = getStringPreferenceValue(normalizedContent, 'debug_http_host');
|
|
75
|
+
const contentWithBackup = existingHost == null
|
|
76
|
+
? normalizedContent
|
|
77
|
+
: renameStringPreference(stripStringPreference(normalizedContent, DEBUG_HTTP_HOST_BACKUP_KEY), 'debug_http_host', DEBUG_HTTP_HOST_BACKUP_KEY);
|
|
78
|
+
const nextContent = insertBeforeClosingMap(contentWithBackup, getHarnessDebugHttpHostBlock(host));
|
|
79
|
+
await writeSharedPrefsFile(adbId, bundleId, nextContent);
|
|
80
|
+
};
|
|
81
|
+
export const clearHarnessDebugHttpHost = async (adbId, bundleId) => {
|
|
82
|
+
const existingContent = await readSharedPrefsFile(adbId, bundleId);
|
|
83
|
+
if (!existingContent) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const nextContentWithoutHarnessBlock = stripHarnessDebugHttpHostBlock(existingContent).trim();
|
|
87
|
+
if (nextContentWithoutHarnessBlock === existingContent.trim()) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const restoredContent = renameStringPreference(nextContentWithoutHarnessBlock, DEBUG_HTTP_HOST_BACKUP_KEY, 'debug_http_host');
|
|
91
|
+
await writeSharedPrefsFile(adbId, bundleId, normalizeEmptyMap(restoredContent).trim());
|
|
92
|
+
};
|