自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
多目标准备器
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
与目标准备器类似,多目标准备器允许同时设置多个设备。例如,当通过蓝牙连接两个设备进行测试时,将使用此功能。
基础接口
基础接口是 IMultiTargetPreparer
,用于实现要执行的 setUp
方法。建议您实现我们的基本抽象类 BaseMultiTargetPreparer
,它提供了内置的停用功能来轻松停用准备器。
多目标准备器还直接为任何清理操作提供 tearDown
方法。
建议
我们建议将每个准备器仅用于一项主要功能。这样,就可以更容易地重复使用准备器。
此外,请在添加新的准备器之前检查可用准备器的列表,以避免重复工作。准备器位于 tools/tradefederation/core/src/com/android/tradefed/targetprep/multi/
。
多目标准备器可以设置的设备数量没有限制。所有设备都会出现在要实现的接口的 IInvocationContext
中。
XML 配置
对象标记为 multi_target_preparer
,例如:
<multi_target_preparer class="com.android.tradefed.targetprep.multi.HelloWorldMultiTargetPreparer">
</multi_target_preparer>
操作顺序
multi_target_preparer
在 target_preparer
之后执行 setUp
multi_target_preparer
在目标清理器执行之前执行 tearDown
这样并不总是允许执行所有设置步骤,因此可以在 XML 中将多目标准备器定义为 multi_pre_target_preparer
,并在 target_preparer
实例之前执行。
<multi_pre_target_preparer class="com.android.tradefed.targetprep.multi.HelloWorldMultiTargetPreparer">
</multi_pre_target_preparer>
整体操作顺序如下:
multi_pre_target_preparer setUp
target_preparer setUp
multi_target_preparer setUp
multi_target_preparer tearDown
target_preparer tearDown
multi_pre_target_preparer tearDown
任何多目标准备器都可以声明为 multi_target_preparer
或 multi_pre_target_preparer
,具体取决于所需的设置顺序。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Multi-target preparers\n\nSimilar to a\n[target preparer](/docs/core/tests/tradefed/architecture/target-preparer), a\nmulti-target preparer allows setup of multiple devices together. For example,\nthis would be used when connecting two devices with Bluetooth for testing.\n\nBase interface\n--------------\n\nThe base interface is\n[`IMultiTargetPreparer`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/multi/IMultiTargetPreparer.java),\nwhich allows implementing a `setUp` method to be executed. We recommend\nimplementing our basic abstract class\n[`BaseMultiTargetPreparer`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/multi/BaseMultiTargetPreparer.java),\nwhich provides a built-in disablement feature to easily disable a preparer.\n\nMulti-target preparers also directly provide a `tearDown` method for any cleanup\noperation.\n\nRecommendation\n--------------\n\nWe recommend limiting each preparer to a single main function. This allows\nfor easier reuse of preparers.\n\nAlso check the list of available preparers before adding a new one, to\navoid duplicating work. Preparers are available in\n[`tools/tradefederation/core/src/com/android/tradefed/targetprep/multi/`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/multi).\n\nThere's no limit to the number of devices that a multi-target preparer can\nset up. All the devices are available in `IInvocationContext` of the\ninterface to implement.\n\nXML configuration\n-----------------\n\nThe object tag is `multi_target_preparer`, for example: \n\n \u003cmulti_target_preparer class=\"com.android.tradefed.targetprep.multi.HelloWorldMultiTargetPreparer\"\u003e\n \u003c/multi_target_preparer\u003e\n\nOperation order\n---------------\n\n1. `multi_target_preparer` executes `setUp` **after** `target_preparer`.\n2. `multi_target_preparer` executes `tearDown` **before** target cleaners.\n\nThis doesn't always allow for performance of all setup steps, so it's possible\nin the XML to define the multi-target preparer as `multi_pre_target_preparer`\nand execute it before `target_preparer` instances. \n\n \u003cmulti_pre_target_preparer class=\"com.android.tradefed.targetprep.multi.HelloWorldMultiTargetPreparer\"\u003e\n \u003c/multi_pre_target_preparer\u003e\n\nThe overall operation order is as followed:\n\n1. `multi_pre_target_preparer setUp`\n2. `target_preparer setUp`\n3. `multi_target_preparer setUp`\n4. `multi_target_preparer tearDown`\n5. `target_preparer tearDown`\n6. `multi_pre_target_preparer tearDown`\n\nAny multi-target preparer can be declared as `multi_target_preparer` or\n`multi_pre_target_preparer` depending of what order of setup is required."]]