← Back to Skills Marketplace
githubzyq

Android Stack Analyzer

by zyq · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
39
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install android-stack-analyzer
Description
Quickly view and analyze Android device page stacks including current page, Activity history, Fragments, and monitor page switches via ADB commands.
README (SKILL.md)

Android Stack Analyzer - 安卓页面栈分析工具

简介

这个技能让你通过ADB命令快速查看安卓设备的页面栈信息,包括当前页面、Activity历史、Fragment等。适用于Android开发者、测试人员和逆向工程师。

功能特点

  • 查看当前最上层页面
  • 分析完整Activity页面栈
  • 查看Fragment页面栈
  • 监控页面切换
  • 支持不同Android版本的命令兼容性

使用方法

1. 查看当前最上层页面

Windows:

adb shell "dumpsys window | findstr mCurrentFocus"

Linux/macOS:

adb shell "dumpsys window | grep mCurrentFocus"

输出示例:

mCurrentFocus=Window{... u0 com.example.app/com.example.app.MainActivity}

2. 查看完整Activity页面栈

Windows:

adb shell "dumpsys activity activities | findstr /R "Hist\|ResumedActivity\|mFocusedActivity"

Linux/macOS:

adb shell "dumpsys activity activities | grep -E 'Hist|ResumedActivity|mFocusedActivity'"

输出示例:

* Hist #3: ActivityRecord{... u0 com.example.app/.activity.MainActivity t533}
* Hist #2: ActivityRecord{... u0 com.example.app/.activity.SettingsActivity t533}
ResumedActivity: ActivityRecord{... u0 com.example.app/.activity.MainActivity t533}

3. 查看页面栈中的Fragment

Windows:

adb shell "dumpsys activity \x3C包名>"

示例:查看com.example.app的Fragment信息

adb shell "dumpsys activity com.example.app"

Linux/macOS:

adb shell "dumpsys activity \x3C包名>"

示例:查看com.example.app的Fragment信息

adb shell "dumpsys activity com.example.app"

4. 查看Activity任务栈树形结构

Windows:

adb shell "dumpsys activity activities | findstr /R "TaskRecord\|ActivityRecord"

Linux/macOS:

adb shell "dumpsys activity activities | grep -E 'TaskRecord|ActivityRecord'"

5. 查看最近任务列表

Windows:

adb shell "dumpsys activity recents"

Linux/macOS:

adb shell "dumpsys activity recents"

6. 实时监控当前页面切换

Windows:

adb shell "while /l %%i in () do @echo [%time%] & adb shell "dumpsys window | findstr mCurrentFocus" & timeout /t 1 > nul"

Linux/macOS:

adb shell "while true; do echo "[$(date '+%H:%M:%S')] $(adb shell 'dumpsys window | grep mCurrentFocus')"; sleep 1; done"

7. 查看Activity生命周期状态

Windows:

adb shell "dumpsys activity activities | findstr state="

Linux/macOS:

adb shell "dumpsys activity activities | grep 'state='"

高级用法

查看特定包名的详细Activity信息

Windows:

adb shell "dumpsys activity a \x3C包名>"

Linux/macOS:

adb shell "dumpsys activity a \x3C包名>"

查看所有运行中的进程及对应的Activity

Windows:

adb shell "dumpsys activity processes"

Linux/macOS:

adb shell "dumpsys activity processes"

查看Back Stack详细信息

Windows:

adb shell "dumpsys activity activities | findstr /R "mResumedActivity\|mFocusedActivity"

Linux/macOS:

adb shell "dumpsys activity activities | grep -E 'mResumedActivity|mFocusedActivity'"

输出解析

mCurrentFocus字段

  • u0 - 用户应用(User app)
  • s0 - 系统应用(System app)
  • com.example.app - 包名
  • com.example.app.MainActivity - Activity类名

Activity历史栈

  • * Hist #3 - 历史记录中的第3个Activity(数字越大越新)
  • u0 - 用户应用
  • t533 - 任务ID
  • inHistory=true - 在历史栈中
  • mStartingWindowState=STARTING_WINDOW_NOT_SHOWN - 启动窗口状态

Activity状态

  • INITIALIZING - 初始化中
  • RESUMED - 前台可见
  • PAUSED - 暂停
  • STOPPED - 停止
  • DESTROYED - 已销毁

兼容性说明

Windows平台

  • 使用 adb 而不是 adb.exe(通常PATH中已配置)
  • 使用 findstr 而不是 grep
  • 使用 findstr /R 进行正则匹配
  • 命令示例:
adb shell "dumpsys window | findstr mCurrentFocus"

Linux/macOS平台

  • 使用 adb 命令
  • 使用 grep 命令
  • 支持正则表达式匹配
  • 命令示例:
adb shell "dumpsys window | grep mCurrentFocus"

Android版本差异

  • Android 13+ 部分 dumpsys 输出格式有变化
  • 如果命令不生效,可以先查看原始输出确认字段名
  • 某些设备可能需要root权限才能获取完整信息

常见问题

1. findstr/grep命令不可用

某些设备上可能没有这些命令,可以:

  • 使用 adb shell dumpsys window 然后手动查找
  • 使用 adb shell dumpsys activity activities 然后手动查找

2. 输出太多信息

可以使用包名过滤:

adb shell "dumpsys activity activities | grep com.example.app"

3. 系统应用信息被隐藏

某些设备可能需要开启开发者选项中的"显示系统级应用"

4. 页面栈不准确

  • 可能是WebView或Dialog/PopupWindow遮挡
  • 可以使用 dumpsys activity activities | grep ResumedActivity 确认

实用脚本

自动化脚本示例

#!/bin/bash
# 获取当前页面
echo "=== 当前页面 ==="
adb shell "dumpsys window | grep mCurrentFocus"

# 获取页面栈
echo -e "\
=== 页面栈 ==="
adb shell "dumpsys activity activities | grep -E 'Hist|ResumedActivity'"

# 获取最近任务
echo -e "\
=== 最近任务 ==="
adb shell "dumpsys activity recents"

批量检查多个应用

#!/bin/bash
apps=("com.example.app1" "com.example.app2" "com.example.app3")

for app in "${apps[@]}"; do
    echo "=== 检查 $app ==="
    adb shell "dumpsys activity activities | grep $app"
    echo ""
done

注意事项

  1. 确保设备已开启USB调试模式
  2. 某些设备可能需要授权ADB连接
  3. 系统应用信息可能需要root权限
  4. 不同Android版本输出格式可能不同
  5. 部分设备可能禁用了某些dumpsys命令

更新日志

  • v1.0.0 - 初始版本,支持基本页面栈分析功能
  • v1.1.0 - 添加Fragment查看功能
  • v1.2.0 - 添加实时监控功能
  • v1.3.0 - 添加跨平台兼容性支持
Usage Guidance
Install only if you intend to use ADB on devices you own or are authorized to debug. Treat dumpsys, getprop, and logcat output as potentially sensitive, redact package names or logs before sharing, and run real-time monitoring only when you explicitly need it.
Capability Assessment
Purpose & Capability
The stated purpose is Android page-stack analysis, and the artifacts consistently provide ADB dumpsys commands and small helper scripts for current Activity, history, recents, fragments, and monitoring.
Instruction Scope
Some activation phrases such as "adb 命令" and "当前页面" are broad, but the runtime behavior remains aligned with Android debugging and requires an attached, ADB-authorized device or explicit script execution.
Install Mechanism
Installation is manual copying into a LobsterAI skills directory, plus optional chmod/PATH setup for ADB; there is no hidden installer, dependency fetch, network setup, or automatic execution.
Credentials
ADB commands like dumpsys, getprop, and logcat can expose device, app, task, and log information, but that access is expected for this debugging purpose and is disclosed through the command examples.
Persistence & Privilege
The skill does not create background services or persistent privileged hooks; monitoring scripts run only when invoked and stop with Ctrl+C.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install android-stack-analyzer
  3. After installation, invoke the skill by name or use /android-stack-analyzer
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Android Stack Analyzer 1.0.0 - Initial release with core page stack analysis tools for Android devices - Supports viewing the current foreground Activity, complete Activity back stack, and Fragment stack - Includes commands for real-time page switch monitoring and recent tasks - Provides cross-platform compatibility (Windows, Linux, macOS) - Offers detailed command examples and practical usage scripts
Metadata
Slug android-stack-analyzer
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Android Stack Analyzer?

Quickly view and analyze Android device page stacks including current page, Activity history, Fragments, and monitor page switches via ADB commands. It is an AI Agent Skill for Claude Code / OpenClaw, with 39 downloads so far.

How do I install Android Stack Analyzer?

Run "/install android-stack-analyzer" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Android Stack Analyzer free?

Yes, Android Stack Analyzer is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Android Stack Analyzer support?

Android Stack Analyzer is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Android Stack Analyzer?

It is built and maintained by zyq (@githubzyq); the current version is v1.0.0.

💬 Comments