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  */
16 package 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  * @since API Level 16
25  */
26 public interface UiWatcher {
27 
28     /**
29      * Custom handler that is automatically called when the testing framework is unable to
30      * find a match using the {@link UiSelector}
31      *
32      * When the framework is in the process of matching a {@link UiSelector} and it
33      * is unable to match any widget based on the specified criteria in the selector,
34      * the framework will perform retries for a predetermined time, waiting for the display
35      * to update and show the desired widget. While the framework is in this state, it will call
36      * registered watchers' checkForCondition(). This gives the registered watchers a chance
37      * to take a look at the display and see if there is a recognized condition that can be
38      * handled and in doing so allowing the current test to continue.
39      *
40      * An example usage would be to look for dialogs popped due to other background
41      * processes requesting user attention and have nothing to do with the application
42      * currently under test.
43      *
44      * @return true to indicate a matched condition or false for nothing was matched
45      * @since API Level 16
46      */
checkForCondition()47     public boolean checkForCondition();
48 }
49