1e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu/*
2e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * Copyright (C) 2012 The Android Open Source Project
3e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu *
4e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * Licensed under the Apache License, Version 2.0 (the "License");
5e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * you may not use this file except in compliance with the License.
6e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * You may obtain a copy of the License at
7e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu *
8e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu *      http://www.apache.org/licenses/LICENSE-2.0
9e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu *
10e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * Unless required by applicable law or agreed to in writing, software
11e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * distributed under the License is distributed on an "AS IS" BASIS,
12e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * See the License for the specific language governing permissions and
14e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * limitations under the License.
15e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu */
16e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhupackage com.android.uiautomator.core;
17e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu
18e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu/**
19e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * See {@link UiDevice#registerWatcher(String, UiWatcher)} on how to register a
20e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * a condition watcher to be called by the automation library. The automation library will
21e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * invoke checkForCondition() only when a regular API call is in retry mode because it is unable
22e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * to locate its selector yet. Only during this time, the watchers are invoked to check if there is
23e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu * something else unexpected on the screen.
24e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu */
25e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhupublic interface UiWatcher {
26a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz
27a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz    /**
28a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * Custom handler that is automatically called when the testing framework is unable to
29a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * find a match using the {@link UiSelector}
30a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     *
31a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * When the framework is in the process of matching a {@link UiSelector} and it
32a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * is unable to match any widget based on the specified criteria in the selector,
33a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * the framework will perform retries for a predetermined time, waiting for the display
34a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * to update and show the desired widget. While the framework is in this state, it will call
35a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * registered watchers' checkForCondition(). This gives the registered watchers a chance
36a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * to take a look at the display and see if there is a recognized condition that can be
37a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * handled and in doing so allowing the current test to continue.
38a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     *
39a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * An example usage would be to look for dialogs popped due to other background
40a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * processes requesting user attention and have nothing to do with the application
41a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * currently under test.
42a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     *
43a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     * @return true to indicate a matched condition or false for nothing was matched
44a46ac3504426564954292b13380120e8cc6b1527Adam Momtaz     */
45e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu    public boolean checkForCondition();
46e54d649fb83a0a44516e5c25a9ac1992c8950e59Guang Zhu}
47