Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 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 | */ |
Brett Chabot | 5fecdaf | 2010-06-03 17:01:08 -0700 | [diff] [blame] | 23 | public interface IDeviceStateMonitor { |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 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 | * |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 34 | * @return the {@link IDevice} if device becomes online before time expires. <code>null</code> |
| 35 | * otherwise. |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 36 | */ |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 37 | public IDevice waitForDeviceOnline(long time); |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 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 | * |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 46 | * @return the {@link IDevice} if device becomes online before time expires. <code>null</code> |
| 47 | * otherwise. |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 48 | */ |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 49 | public IDevice waitForDeviceOnline(); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
wsmlby | f0437ea | 2014-08-22 15:01:11 -0700 | [diff] [blame] | 52 | * Blocks until the device's boot complete flag is set |
| 53 | * |
| 54 | * @param waitTime the amount in ms to wait |
| 55 | */ |
| 56 | public boolean waitForBootComplete(final long waitTime); |
| 57 | |
| 58 | /** |
Brett Chabot | 0150090 | 2011-07-19 19:27:38 -0700 | [diff] [blame] | 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 | */ |
| 64 | public boolean waitForDeviceShell(final long waitTime); |
| 65 | |
| 66 | /** |
Brett Chabot | 4d180a5 | 2011-07-07 17:59:42 -0700 | [diff] [blame] | 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. |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 69 | * |
| 70 | * @param waitTime the time in ms to wait |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 71 | * @return the {@link IDevice} if device becomes online before time expires. <code>null</code> |
| 72 | * otherwise. |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 73 | */ |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 74 | public IDevice waitForDeviceAvailable(final long waitTime); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 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 | * |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 82 | * @return the {@link IDevice} if device becomes online before time expires. <code>null</code> |
| 83 | * otherwise. |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 84 | */ |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 85 | public IDevice waitForDeviceAvailable(); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Waits for the device to be in bootloader. |
| 89 | * |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 90 | * @param waitTime the maximum time in ms to wait |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 91 | * |
| 92 | * @return <code>true</code> if device is in bootloader before time expires |
| 93 | */ |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 94 | public boolean waitForDeviceBootloader(long waitTime); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Brett Chabot | 467ac2b | 2010-07-30 16:44:47 -0700 | [diff] [blame] | 97 | * Waits for device bootloader state to be refreshed |
| 98 | */ |
| 99 | public void waitForDeviceBootloaderStateUpdate(); |
| 100 | |
| 101 | /** |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 102 | * Waits for the device to be not available |
| 103 | * |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 104 | * @param waitTime the maximum time in ms to wait |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 105 | * |
| 106 | * @return <code>true</code> if device becomes unavailable |
| 107 | */ |
Brett Chabot | 93e0782 | 2010-05-12 16:52:18 -0700 | [diff] [blame] | 108 | public boolean waitForDeviceNotAvailable(long waitTime); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 109 | |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 110 | /** |
Brett Chabot | 70ac3fd | 2011-01-17 13:38:59 -0800 | [diff] [blame] | 111 | * Waits for the device to be in the 'adb recovery' state |
| 112 | * |
| 113 | * @param waitTime the maximum time in ms to wait |
Julien Desprez | ac32e66 | 2016-07-05 10:59:32 +0100 | [diff] [blame] | 114 | * @return True if the device is in Recovery before the timeout, False otherwise. |
Brett Chabot | 70ac3fd | 2011-01-17 13:38:59 -0800 | [diff] [blame] | 115 | */ |
| 116 | public boolean waitForDeviceInRecovery(long waitTime); |
| 117 | |
| 118 | /** |
Guang Zhu | ac76f7a | 2019-05-22 16:46:23 -0700 | [diff] [blame^] | 119 | * Waits for the device to be in the 'adb sideload' state |
| 120 | * |
| 121 | * @param waitTime the maximum time in ms to wait |
| 122 | * @return True if the device is in sideload before the timeout, False otherwise. |
| 123 | */ |
| 124 | public boolean waitForDeviceInSideload(long waitTime); |
| 125 | |
| 126 | /** |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 127 | * Gets the serial number of the device. |
| 128 | */ |
| 129 | public String getSerialNumber(); |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * Gets the device state. |
| 133 | * |
| 134 | * @return the {@link TestDeviceState} of device |
| 135 | */ |
| 136 | public TestDeviceState getDeviceState(); |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 139 | * Sets the device current state. |
| 140 | * |
Brett Chabot | ac3a79e | 2010-05-26 13:46:36 -0700 | [diff] [blame] | 141 | * @param deviceState |
| 142 | */ |
| 143 | public void setState(TestDeviceState deviceState); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Returns a mount point. |
| 147 | * <p/> |
| 148 | * Queries the device directly if the cached info in {@link IDevice} is not available. |
| 149 | * <p/> |
| 150 | * TODO: move this behavior to {@link IDevice#getMountPoint(String)} |
| 151 | * |
| 152 | * @param mountName the name of the mount point |
| 153 | * @return the mount point or <code>null</code> |
Julien Desprez | ac32e66 | 2016-07-05 10:59:32 +0100 | [diff] [blame] | 154 | * @see IDevice#getMountPoint(String) |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 155 | */ |
| 156 | public String getMountPoint(String mountName); |
Brett Chabot | 467ac2b | 2010-07-30 16:44:47 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * Updates the current IDevice. |
| 160 | * |
| 161 | * @param device |
| 162 | * |
Julien Desprez | ac32e66 | 2016-07-05 10:59:32 +0100 | [diff] [blame] | 163 | * @see IManagedTestDevice#setIDevice(IDevice) |
Brett Chabot | 467ac2b | 2010-07-30 16:44:47 -0700 | [diff] [blame] | 164 | */ |
| 165 | public void setIDevice(IDevice device); |
Brett Chabot | cb6bf63 | 2011-03-17 00:08:13 -0700 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * @return <code>true</code> if device is connected to adb via tcp |
| 169 | */ |
| 170 | public boolean isAdbTcp(); |
| 171 | |
Brett Chabot | 8b52b9b | 2012-05-02 11:35:50 -0700 | [diff] [blame] | 172 | /** |
| 173 | * Set the time in ms to wait for a device to be online in {@link #waitForDeviceOnline()}. |
| 174 | */ |
| 175 | public void setDefaultOnlineTimeout(long timeoutMs); |
| 176 | |
| 177 | /** |
| 178 | * Set the time in ms to wait for a device to be available in {@link #waitForDeviceAvailable()}. |
| 179 | */ |
| 180 | public void setDefaultAvailableTimeout(long timeoutMs); |
| 181 | |
Brett Chabot | 4e54a1f | 2010-05-10 19:46:36 -0700 | [diff] [blame] | 182 | } |