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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值