• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.tradefed.device;
17 
18 import com.android.ddmlib.IDevice;
19 
20 /**
21  * Provides facilities for monitoring the state of a {@link IDevice}.
22  */
23 public interface IDeviceStateMonitor {
24 
25     /**
26      * Waits for device to be online.
27      * <p/>
28      * Note: this method will return once device is visible via DDMS. It does not guarantee that the
29      * device is actually responsive to adb commands - use {@link #waitForDeviceAvailable()}
30      * instead.
31      *
32      * @param time the maximum time in ms to wait
33      *
34      * @return the {@link IDevice} if device becomes online before time expires. <code>null</code>
35      * otherwise.
36      */
waitForDeviceOnline(long time)37     public IDevice waitForDeviceOnline(long time);
38 
39     /**
40      * Waits for device to be online using standard boot timeout.
41      * <p/>
42      * Note: this method will return once device is visible via DDMS. It does not guarantee that the
43      * device is actually responsive to adb commands - use {@link #waitForDeviceAvailable()}
44      * instead.
45      *
46      * @return the {@link IDevice} if device becomes online before time expires. <code>null</code>
47      * otherwise.
48      */
waitForDeviceOnline()49     public IDevice waitForDeviceOnline();
50 
51     /**
52      * Blocks until the device's boot complete flag is set
53      *
54      * @param waitTime the amount in ms to wait
55      */
waitForBootComplete(final long waitTime)56     public boolean waitForBootComplete(final long waitTime);
57 
58     /**
59      * Waits for device to be responsive to a basic adb shell command.
60      *
61      * @param waitTime the time in ms to wait
62      * @return <code>true</code> if device becomes responsive before <var>waitTime</var> elapses.
63      */
waitForDeviceShell(final long waitTime)64     public boolean waitForDeviceShell(final long waitTime);
65 
66     /**
67      * Waits for the device to be responsive and available for testing. Currently this means that
68      * the package manager and external storage are available.
69      *
70      * @param waitTime the time in ms to wait
71      * @return the {@link IDevice} if device becomes online before time expires. <code>null</code>
72      * otherwise.
73      */
waitForDeviceAvailable(final long waitTime)74     public IDevice waitForDeviceAvailable(final long waitTime);
75 
76     /**
77      * Waits for the device to be responsive and available for testing.
78      * <p/>
79      * Equivalent to {@link #waitForDeviceAvailable(long)}, but uses default device
80      * boot timeout.
81      *
82      * @return the {@link IDevice} if device becomes online before time expires. <code>null</code>
83      * otherwise.
84      */
waitForDeviceAvailable()85     public IDevice waitForDeviceAvailable();
86 
87     /**
88      * Waits for the device to be in bootloader.
89      *
90      * @param waitTime the maximum time in ms to wait
91      *
92      * @return <code>true</code> if device is in bootloader before time expires
93      */
waitForDeviceBootloader(long waitTime)94     public boolean waitForDeviceBootloader(long waitTime);
95 
96     /**
97      * Waits for device bootloader state to be refreshed
98      */
waitForDeviceBootloaderStateUpdate()99     public void waitForDeviceBootloaderStateUpdate();
100 
101     /**
102      * Waits for the device to be not available
103      *
104      * @param waitTime the maximum time in ms to wait
105      *
106      * @return <code>true</code> if device becomes unavailable
107      */
waitForDeviceNotAvailable(long waitTime)108     public boolean waitForDeviceNotAvailable(long waitTime);
109 
110     /**
111      * Waits for the device to be in the 'adb recovery' state
112      *
113      * @param waitTime the maximum time in ms to wait
114      * @return True if the device is in Recovery before the timeout, False otherwise.
115      */
waitForDeviceInRecovery(long waitTime)116     public boolean waitForDeviceInRecovery(long waitTime);
117 
118     /**
119      * Gets the serial number of the device.
120      */
getSerialNumber()121     public String getSerialNumber();
122 
123     /**
124      * Gets the device state.
125      *
126      * @return the {@link TestDeviceState} of device
127      */
getDeviceState()128     public TestDeviceState getDeviceState();
129 
130     /**
131      * Sets the device current state.
132      *
133      * @param deviceState
134      */
setState(TestDeviceState deviceState)135     public void setState(TestDeviceState deviceState);
136 
137     /**
138      * Returns a mount point.
139      * <p/>
140      * Queries the device directly if the cached info in {@link IDevice} is not available.
141      * <p/>
142      * TODO: move this behavior to {@link IDevice#getMountPoint(String)}
143      *
144      * @param mountName the name of the mount point
145      * @return the mount point or <code>null</code>
146      * @see IDevice#getMountPoint(String)
147      */
getMountPoint(String mountName)148     public String getMountPoint(String mountName);
149 
150     /**
151      * Updates the current IDevice.
152      *
153      * @param device
154      *
155      * @see IManagedTestDevice#setIDevice(IDevice)
156      */
setIDevice(IDevice device)157     public void setIDevice(IDevice device);
158 
159     /**
160      * @return <code>true</code> if device is connected to adb via tcp
161      */
isAdbTcp()162     public boolean isAdbTcp();
163 
164     /**
165      * Set the time in ms to wait for a device to be online in {@link #waitForDeviceOnline()}.
166      */
setDefaultOnlineTimeout(long timeoutMs)167     public void setDefaultOnlineTimeout(long timeoutMs);
168 
169     /**
170      * Set the time in ms to wait for a device to be available in {@link #waitForDeviceAvailable()}.
171      */
setDefaultAvailableTimeout(long timeoutMs)172     public void setDefaultAvailableTimeout(long timeoutMs);
173 
174 }
175