118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu/*
218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Copyright (C) 2012 The Android Open Source Project
318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu *
418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Licensed under the Apache License, Version 2.0 (the "License");
518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * you may not use this file except in compliance with the License.
618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * You may obtain a copy of the License at
718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu *
818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu *      http://www.apache.org/licenses/LICENSE-2.0
918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu *
1018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * Unless required by applicable law or agreed to in writing, software
1118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * distributed under the License is distributed on an "AS IS" BASIS,
1218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * See the License for the specific language governing permissions and
1418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * limitations under the License.
1518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu */
1618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhupackage com.android.uiautomator.core;
1718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
1818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu/**
1918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * See {@link UiDevice#registerWatcher(String, UiWatcher)} on how to register a
2018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * a condition watcher to be called by the automation library. The automation library will
2118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * invoke checkForCondition() only when a regular API call is in retry mode because it is unable
2218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * to locate its selector yet. Only during this time, the watchers are invoked to check if there is
2318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * something else unexpected on the screen.
2418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu * @since API Level 16
253fb03313e9d0e41f7c14b648c0f4dcfdab78bff3Allen Hair * @deprecated New tests should be written using UI Automator 2.0 which is available as part of the
263fb03313e9d0e41f7c14b648c0f4dcfdab78bff3Allen Hair * Android Testing Support Library.
2718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu */
283fb03313e9d0e41f7c14b648c0f4dcfdab78bff3Allen Hair@Deprecated
2918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhupublic interface UiWatcher {
3018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu
3118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    /**
3218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * Custom handler that is automatically called when the testing framework is unable to
3318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * find a match using the {@link UiSelector}
3418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     *
3518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * When the framework is in the process of matching a {@link UiSelector} and it
3618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * is unable to match any widget based on the specified criteria in the selector,
3718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * the framework will perform retries for a predetermined time, waiting for the display
3818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * to update and show the desired widget. While the framework is in this state, it will call
3918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * registered watchers' checkForCondition(). This gives the registered watchers a chance
4018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * to take a look at the display and see if there is a recognized condition that can be
4118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * handled and in doing so allowing the current test to continue.
4218b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     *
4318b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * An example usage would be to look for dialogs popped due to other background
4418b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * processes requesting user attention and have nothing to do with the application
4518b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * currently under test.
4618b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     *
4718b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * @return true to indicate a matched condition or false for nothing was matched
4818b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     * @since API Level 16
4918b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu     */
5018b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu    public boolean checkForCondition();
5118b892c723e812a7e111f102d2b0c0782b116bb6Guang Zhu}
52