gpt4 book ai didi

android - UiAutomation vs AccessibilityService

转载 作者:行者123 更新时间:2023-12-04 12:23:23 25 4
gpt4 key购买 nike

doc's它说这是关于 UiAutomation

Class for interacting with the device's UI by simulation user actionsand introspection of the screen content. It relies on the platformaccessibility APIs to introspect the screen and to perform someactions on the remote view tree. It also allows injecting of arbitraryraw input events simulating user interaction with keyboards and touchdevices. One can think of a UiAutomation as a special type ofAccessibilityService which does not provide hooks for the service lifecycle and exposes other APIs that are useful for UI test automation.

The APIs exposed by this class are low-level to maximize flexibilitywhen developing UI test automation tools and libraries. Generally, aUiAutomation client should be using a higher-level library orimplement high-level functions. For example, performing a tap on thescreen requires construction and injecting of a touch down and upevents which have to be delivered to the system by a call toinjectInputEvent(android.view.InputEvent, boolean).

The APIs exposed by this class operate across applications enabling aclient to write tests that cover use cases spanning over multipleapplications. For example, going to the settings application to changea setting and then interacting with another application whose behaviordepends on that setting.

UiAutomation到底是怎样的?不同于普通的 AccessibilityService ,因为它不会在 source code 中继承它.
public final class UiAutomation {
private static final String LOG_TAG = UiAutomation.class.getSimpleName();
// omitted the rest...

最佳答案

无障碍服务:

should only be used to assist users with disabilities in using Androiddevices and apps. They run in the background and receive [...] AccessibilityEvents [...]. Such events denote somestate transition in the user interface, for example, the focus haschanged, a button has been clicked, etc. Such a service can optionallyrequest the capability for querying the content of the active window.


这是一个强大的工具,可以让您访问手机上发生的所有事情,因此用户需要在手机设置中明确启用此类服务​​(通常在辅助功能/已安装服务下)。
Ui自动化:
好吧,您基本上引用了问题中的描述,但在这里您有一个更详细的描述:
在某些方面,UiAutomation 充当修饰的 AccessibilityService ( decorator design pattern .)。您可以阅读方法 getServiceInfo 和 setServiceInfo 的源代码来验证它,它们在内部使用连接的服务对应项(检查导入以快速查看)。
这是一个添加一些功能的包装器,例如它允许您导航 View 层次结构等,而无需在每次首次运行检测测试时在手机设置中启用可访问性服务。这是在 android.app.Instumentation 类和其他测试框架组件的帮助下实现的。系统可以安全地授予所需的权限,因为检测 can only be started through adb or from within a System App .
这不是真正的 AccessibilityService(甚至不是真正的服务),但为了简单起见并引起对底层环境的注意,它可能被称为这种方式。

关于android - UiAutomation vs AccessibilityService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64772554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com