UiAutomation 与 AccessibilityService [英] UiAutomation vs AccessibilityService

查看:53
本文介绍了UiAutomation 与 AccessibilityService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

doc's 中,它是关于 UiAutomation 的代码>

In the doc's it say this about UiAutomation

通过模拟用户操作与设备的 UI 交互的类以及画面内容的内省.它依赖于平台用于检查屏幕并执行一些操作的辅助功能 API远程视图树上的操作.它还允许注入任意模拟用户与键盘和触摸交互的原始输入事件设备.可以将 UiAutomation 视为一种特殊类型的AccessibilityService 不提供服务寿命的钩子循环并公开其他对 UI 测试自动化有用的 API.

Class for interacting with the device's UI by simulation user actions and introspection of the screen content. It relies on the platform accessibility APIs to introspect the screen and to perform some actions on the remote view tree. It also allows injecting of arbitrary raw input events simulating user interaction with keyboards and touch devices. One can think of a UiAutomation as a special type of AccessibilityService which does not provide hooks for the service life cycle and exposes other APIs that are useful for UI test automation.

此类公开的 API 是低级的,以最大限度地提高灵活性在开发 UI 测试自动化工具和库时.一般来说,一个UiAutomation 客户端应该使用更高级别的库或实现高级功能.例如,执行点击屏幕需要构建和注入触摸向下和向上必须通过调用传递给系统的事件注入输入事件(android.view.InputEvent,布尔值).

The APIs exposed by this class are low-level to maximize flexibility when developing UI test automation tools and libraries. Generally, a UiAutomation client should be using a higher-level library or implement high-level functions. For example, performing a tap on the screen requires construction and injecting of a touch down and up events which have to be delivered to the system by a call to injectInputEvent(android.view.InputEvent, boolean).

此类公开的 API 可跨应用程序运行,从而实现客户端编写涵盖跨越多个用例的测试应用程序.例如,转到设置应用程序进行更改一个设置,然后与其行为的另一个应用程序交互取决于那个设置.

The APIs exposed by this class operate across applications enabling a client to write tests that cover use cases spanning over multiple applications. For example, going to the settings application to change a setting and then interacting with another application whose behavior depends on that setting.

UiAutomation 与常规 AccessibilityService 究竟有何不同,因为它在 源代码.

How exactly is UiAutomation different from a regular AccessibilityService, as it doesn't inherit from it in the source code.

public final class UiAutomation {
    private static final String LOG_TAG = UiAutomation.class.getSimpleName();
    // omitted the rest...

推荐答案

无障碍服务:

应仅用于帮助残障用户使用 Android设备和应用程序.它们在后台运行并接收 [...] AccessibilityEvents [...].此类事件表示一些用户界面中的状态转换,例如,焦点有已更改,已单击按钮等.此类服务可以选择请求查询活动窗口内容的能力.

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

这是一个强大的工具,可以让您访问手机上发生的基本上所有事情,因此用户需要在手机设置中明确启用此类服务​​(通常在辅助功能/已安装的服务下).

This is a powerful tool that can give you access to basically everything that happens on your phone, hence the user needs to explicitly enable such service in the phone settings (generally under Accessibility/Installed Services).

UiAutomation:

好吧,您基本上引用了问题中的描述,但这里有一个更详细的描述:

Well you basically quoted the description in your question, but here you have a more detailed one:

在某些方面,UiAutomation 充当装饰的 AccessibilityService(装饰设计模式.).您可以通过阅读 getServiceInfo 和 setServiceInfo 方法的源代码来验证它,它们在内部使用连接的服务对应物(检查导入以快速查看).

In certain way UiAutomation acts as a decorated AccessibilityService (decorator design pattern.). You can verify it reading the source code of the methods getServiceInfo and setServiceInfo, which internally uses the connected service counterparts (check the imports for a quick look).

这是一个添加一些功能的包装器,例如,它允许您导航视图层次结构等,而无需每次首次运行仪器测试时都在手机设置中启用辅助功能服务.这是在 android.app.Instumentation 类和其他测试框架组件的帮助下实现的.系统可以安全地授予所需的权限,因为检测 只能是通过 adb 或从系统应用程序中启动.

This is a wrapper that adds some functionality, for example it allows you to navigate the view hierarchy, etc, without needing to enable the accessibility service in the phone settings every single time you first run an instrumented test. This is achieved with aid of the android.app.Instumentation class and other testing framework components. The system can safely grant the needed permissions because an instrumentation can only be started through adb or from within a System App.

这不是真正的 AccessibilityService(甚至不是真正的服务),但为了简单起见并引起人们对底层环境的注意,可能会这样称呼它.

This is not really an AccessibilityService (Not even a real service), but it's probably called that way for simplicity and to draw attention to the underlaying environment.

这篇关于UiAutomation 与 AccessibilityService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆