adb shell 命令之service调试

在android上有丰富的shell命令用来调试,非常方便,本文通过一个用法来观察下service命令的用法。

  • 首先观察下Usage手册。
C:\Users\xxxx>adb shell service
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 to the send parcel.
   nfd: Write file descriptor n to the send parcel.
   afd: Write an ashmem file descriptor for a region containing the data from file f to the send parcel.
  • 使用 service list 列出所有系统服务
C:\Users\xxxx>adb shell service list
Found 302 services:
... //只贴出了一部分
22      SurfaceFlinger: [android.ui.ISurfaceComposer]
23      SysinfoService: [android.os.ISysinfo]
24      accessibility: [android.view.accessibility.IAccessibilityManager]
25      account: [android.accounts.IAccountManager]
26      activity: [android.app.IActivityManager]
27      activity_task: [android.app.IActivityTaskManager]
...
  • 使用check service 检查服务是否存在
C:\Users\xxx>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 ] …
CODE其实就是binder机制中,onTransact函数中的第一个参数。后面是参数类型,再加上参数

  1. 尝试一下,打开SurfaceFlinger刷新率并显示在屏幕上
C:\Users\xxx>adb shell service call SurfaceFlinger 1034 i32 1
Result: Parcel(NULL)
  1. 跟踪下源码中的实现
    frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp
    找到下面的函数:
status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
                                    uint32_t flags) {
    
    }|

在这里插入图片描述
可以看到,enableRefreshRateOverlay(static_cast(n))),中的n就是1为开,0为关。

那么尝试关闭的命令可推断为:

C:\Users\xxx>adb shell service call SurfaceFlinger 1034 i32 0
Result: Parcel(NULL)

猜你喜欢

转载自blog.csdn.net/lucky_tom/article/details/126381165
今日推荐