Skip to content

Commit 107384f

Browse files
fix: Update dumpsys windows output parsing logic for API level 33 (#753)
1 parent d717e25 commit 107384f

File tree

2 files changed

+406
-21
lines changed

2 files changed

+406
-21
lines changed

lib/commands/system-bars.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import _ from 'lodash';
22

33
const WINDOW_TITLE_PATTERN = /^\s+Window\s#\d+\sWindow\{[0-9a-f]+\s\w+\s([\w-]+)\}:$/;
4-
const FRAME_PATTERN = /^\s+mFrame=\[([0-9.-]+),([0-9.-]+)\]\[([0-9.-]+),([0-9.-]+)\]/m;
5-
const SURFACE_PATTERN = /^\s+Surface:\sshown=(true|false)/m;
4+
const FRAME_PATTERN = /\bm?[Ff]rame=\[([0-9.-]+),([0-9.-]+)\]\[([0-9.-]+),([0-9.-]+)\]/;
5+
const VIEW_VISIBILITY_PATTERN = /\bmViewVisibility=(0x[0-9a-fA-F]+)/;
6+
// https://developer.android.com/reference/android/view/View#VISIBLE
7+
const VIEW_VISIBLE = 0x0;
68
const STATUS_BAR_WINDOW_NAME_PREFIX = 'StatusBar';
79
const NAVIGATION_BAR_WINDOW_NAME_PREFIX = 'NavigationBar';
810
const DEFAULT_WINDOW_PROPERTIES = {
@@ -43,12 +45,12 @@ function parseWindowProperties (name, props, log = null) {
4345
result.y = parseFloat(frameMatch[2]);
4446
result.width = parseFloat(frameMatch[3]) - result.x;
4547
result.height = parseFloat(frameMatch[4]) - result.y;
46-
const visibilityMatch = SURFACE_PATTERN.exec(propLines);
48+
const visibilityMatch = VIEW_VISIBILITY_PATTERN.exec(propLines);
4749
if (!visibilityMatch) {
4850
log?.debug(propLines);
4951
throw new Error(`Cannot parse the visibility value from '${name}' window properties`);
5052
}
51-
result.visible = visibilityMatch[1] === 'true';
53+
result.visible = parseInt(visibilityMatch[1], 16) === VIEW_VISIBLE;
5254
return result;
5355
}
5456

@@ -65,29 +67,21 @@ function parseWindowProperties (name, props, log = null) {
6567
function parseWindows (lines, log = null) {
6668
const windows = {};
6769
let currentWindowName = null;
68-
let windowNameRowIndent = null;
6970
for (const line of lines.split('\n').map(_.trimEnd)) {
70-
const currentIndent = line.length - _.trimStart(line).length;
71-
if (_.isNil(windowNameRowIndent) || currentIndent <= windowNameRowIndent) {
72-
const match = WINDOW_TITLE_PATTERN.exec(line);
73-
if (!match) {
74-
currentWindowName = null;
75-
continue;
76-
}
71+
const match = WINDOW_TITLE_PATTERN.exec(line);
72+
if (match) {
7773
currentWindowName = match[1];
78-
if (_.isNil(windowNameRowIndent)) {
79-
windowNameRowIndent = currentIndent;
80-
}
74+
windows[currentWindowName] = [];
8175
continue;
8276
}
83-
if (!currentWindowName || currentIndent <= windowNameRowIndent) {
77+
if (_.trim(line).length === 0) {
78+
currentWindowName = null;
8479
continue;
8580
}
8681

87-
if (!_.isArray(windows[currentWindowName])) {
88-
windows[currentWindowName] = [];
82+
if (currentWindowName && _.isArray(windows[currentWindowName])) {
83+
windows[currentWindowName].push(line);
8984
}
90-
windows[currentWindowName].push(line);
9185
}
9286
if (_.isEmpty(windows)) {
9387
log?.debug(lines.join('\n'));

0 commit comments

Comments
 (0)