adb shell service命令与SurfaceFlinger调试

01 基本用法

  • 首先看一下使用说明,带上参数-h 或 -?


$ adb shell service -h
Usage: service [-h|-?]
       service list
       service check SERVICE
       service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null | fd f | nfd n | afd f ] ...
Options:
   i32: Write the 32-bit integer N into the send parcel.
   i64: Write the 64-bit integer N into the send parcel.
     f: Write the 32-bit single-precision number N into the send parcel.
     d: Write the 64-bit double-precision number N into the send parcel.
   s16: Write the UTF-16 string STR into the send parcel.
  null: Write a null binder into the send parcel.
    fd: Write a file descriptor for the file f into the send parcel.
   nfd: Write the file descriptor n into the send parcel.
   afd: Write an ashmem file descriptor for a region containing the data from
          file f into the send parcel.
  • 使用 service list 列出所有系统服务

$ adb shell service list
Found 303 services:
0       DockObserver: []
1       SurfaceFlinger: [android.ui.ISurfaceComposer]
2       SurfaceFlingerAIDL: [android.gui.ISurfaceComposer]
3       accessibility: [android.view.accessibility.IAccessibilityManager]
4       account: [android.accounts.IAccountManager]
5       activity: [android.app.IActivityManager]
6       activity_task: [android.app.IActivityTaskManager]
7       adb: [android.debug.IAdbManager]
8       adservices_manager: [android.app.adservices.IAdServicesManager]
9       alarm: [android.app.IAlarmManager]
....
  • 使用check service 检查服务是否存在

$ adb shell service check SurfaceFlinger
Service SurfaceFlinger: found
  • 使用call service 调用服务

service call SERVICE CODE [i32 N | i64 N | f N | d N | s16 STR | null | fd f | nfd n | afd f ] ...
  • SERVICE 就是list查询到的系统服务的名字;

  • CODE就是就是binder机制中,onTransact函数中的第一个参数;

  • 后面是要传递的参数,参数类型+参数值

02 用法举例

我们用一个例子来说明,如何通过service命令和系统服务互动。

打开SurfaceFlinger刷新率并显示在屏幕上,传递一个int32_t类型的参数,值1打开,值0是关闭:

$ adb shell service call SurfaceFlinger 1034 i32 1
Result: Parcel(NULL)

会看到如下效果:

可以看下源码(下面我截取的是Android 14的源码来解析的):

/frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp

status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                                    uint32_t flags) {
...
            case 1034: {
                auto future = mScheduler->schedule(
                        [&]() FTL_FAKE_GUARD(mStateLock) FTL_FAKE_GUARD(kMainThreadContext) {
                            switch (n = data.readInt32()) {
                                case 0:
                                case 1:
                                    enableRefreshRateOverlay(static_cast<bool>(n));
                                    break;
                                default:
                                    reply->writeBool(isRefreshRateOverlayEnabled());
                            }
                        });
 
                future.wait();
                return NO_ERROR;
            }
...
}

<think>我们正在处理用户关于使用ADB获取SurfaceFlinger信息的问题。根据引用内容,用户需要知道如何获取当前SurfaceFlinger的状态或日志。根据引用[1]和[2],我们可以使用`adb shelldumpsys SurfaceFlinger`命令来获取SurfaceFlinger的dump信息。这个命令会输出很多内容,因此建议将输出重定向到一个文件中以便分析。另外,引用[3]提到了一些关于SurfaceFlinger调试信息,但主要是源码层面的,对于用户来说,直接使用dumpsys命令即可。 引用[5]列出了dumpsys可以使用的各种服务,其中第一个就是SurfaceFlinger。因此,我们可以给用户提供以下步骤: 1.连接设备并确保ADB调试已开启。2.在命令行中执行`adb shelldumpsys SurfaceFlinger`来直接输出信息到控制台。3.如果输出内容过多,可以将输出重定向到文件,例如:`adbshell dumpsysSurfaceFlinger >surface.txt`(文件将保存在当前工作目录)。另外,用户可能还想知道如何获取更详细的日志或者实时日志?但根据问题,用户只需要当前状态,所以dumpsys命令已经足够。 注意:在Android系统中,dumpsys是一个强大的工具,可以获取系统服务的状态信息。SurfaceFlinger是负责显示合成的系统服务,因此通过dumpsys SurfaceFlinger可以获取图层、合成状态等信息。 相关问题: 1.如何分析SurfaceFlinger的输出信息? 2.除了SurfaceFlinger,还有哪些常用的dumpsys服务? 3.如何实时监控SurfaceFlinger的状态变化?</think>### 使用ADB获取SurfaceFlinger信息的方法 在Android设备上获取SurfaceFlinger的当前状态或日志,可通过以下ADB命令实现: 1. **基础命令** 执行以下命令直接输出SurfaceFlinger的实时状态信息到终端: ```bash adb shell dumpsys SurfaceFlinger ``` 此命令会输出包括图层合成状态、显示配置、帧缓冲信息等关键数据[^1][^2]。 2. **输出到文件(推荐)** 由于输出内容较多,建议重定向到文件方便分析: ```bash adb shell dumpsys SurfaceFlinger > surface_log.txt ``` 文件将保存在当前终端的工作目录中(如Windows的`C:\Users\用户名`或Linux的`~/`)[^1]。 3. **高级调试命令** 启用/禁用刷新率叠加层显示(用于调试显示性能): ```bash # 启用刷新率叠加层 adb shell service call SurfaceFlinger 1034 i32 1 # 禁用刷新率叠加层 adb shell service call SurfaceFlinger 1034 i32 0 ``` 该命令通过调用SurfaceFlinger服务的内部接口实现[^3]。 --- ### 关键输出内容解析 生成的日志通常包含以下核心信息: - **图层列表(Layer List)**:所有Surface的Z轴顺序、尺寸和合成状态 - **显示配置(Display Config)**:分辨率、刷新率、HDR支持等 - **帧统计(Frame Statistics)**:丢帧情况、合成延迟 - **硬件配置(HWComposer)**:GPU和显示硬件的使用情况 - **内存状态(Buffer Queues)**:图形缓冲区的分配和使用 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值