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