adb shell service命令与SurfaceFlinger调试

“ 在Android上有丰富的shell命令便于开发者用来调试程序,非常方便,本文简单说明下service命令的用法。

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;
            }
...
}

SurfaceFlinger::onTransact函数中,在收到code=1034的请求后,首先会读取参数,然后

点击阅读原文

adb shell service命令与SurfaceFlinger调试

更多Android Graphics知识

全面解读 Android Graphics 图像显示系统_android图像系统-CSDN博客

`SurfaceFlinger::createBufferQueueLayer()` 是 Android Framework 中 SurfaceFlinger 系统服务中的一个方法,用于创建一个使用 BufferQueue 的 Layer。其函数定义如下: ```c++ sp<Layer> SurfaceFlinger::createBufferQueueLayer(const String8& name, uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, uint32_t layerStack, const sp<IBinder>& parent, const sp<IGraphicBufferProducer>& bufferProducer, const sp<IGraphicBufferConsumer>& bufferConsumer, bool forceClientComposition, uint32_t metadataType) ``` 该函数的参数如下: - `name`:Layer 的名称。 - `w`:Layer 的宽度。 - `h`:Layer 的高度。 - `flags`:Layer 的标志位,如是否支持透明度等。 - `format`:Layer 的像素格式。 - `layerStack`:Layer 所在的层级。 - `parent`:Layer 的父节点。 - `bufferProducer`:Layer 使用的 BufferQueue 的生产者对象。 - `bufferConsumer`:Layer 使用的 BufferQueue 的消费者对象。 - `forceClientComposition`:是否强制使用客户端渲染。 - `metadataType`:Layer 的元数据类型。 该函数的作用是创建一个使用 BufferQueue 的 Layer,BufferQueue 是 Android 中用于处理图形缓冲区的类,它可以用于实现 Surface 的双缓冲机制,以及多个线程之间的数据交换等功能。在这个函数中,会创建一个 Layer 对象,并将其与指定的 BufferQueue 相关联,完成 Layer 的初始化工作。函数返回值为 `sp<Layer>` 类型的智能指针,指向创建的 Layer 对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值