Skip to content

Commit

Permalink
Merge pull request #359 from caofengbin/feature/fix_get_activity_error
Browse files Browse the repository at this point in the history
fix:修复adb shell dumpsys  window displays获取到多个mCurrentFocus时,无法正确得到当前Activity
  • Loading branch information
ZhouYixun authored Jun 14, 2023
2 parents bef0dbe + 5731784 commit bfb0753
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,13 @@ public static String getCurrentActivity(IDevice iDevice) {
String.format("dumpsys window %s", api >= 29 ? "displays" : "windows"));
String result = "";
try {
String start = cmd.substring(cmd.indexOf("mCurrentFocus="));
String end = start.substring(start.indexOf("/") + 1);
result = end.substring(0, end.indexOf("}"));
Pattern pattern = Pattern.compile("mCurrentFocus=(?!null)[^,]+");
Matcher matcher = pattern.matcher(cmd);
if (matcher.find()) {
String start = cmd.substring(matcher.start());
String end = start.substring(start.indexOf("/") + 1);
result = end.substring(0, end.indexOf("}"));
}
} catch (Exception ignored) {
}
if (result.length() == 0) {
Expand Down

0 comments on commit bfb0753

Please sign in to comment.