146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephenspage.title=Working with Devices 246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens@jd:body 346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<!-- 546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens Copyright 2013 The Android Open Source Project 646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens Licensed under the Apache License, Version 2.0 (the "License"); 846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens you may not use this file except in compliance with the License. 946bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens You may obtain a copy of the License at 1046bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 1146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens http://www.apache.org/licenses/LICENSE-2.0 1246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 1346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens Unless required by applicable law or agreed to in writing, software 1446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens distributed under the License is distributed on an "AS IS" BASIS, 1546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens See the License for the specific language governing permissions and 1746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens limitations under the License. 1846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens--> 1946bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 2046bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<p>Trade Federation uses an abstraction called 2146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<code><a href="/reference/com/android/tradefed/device/ITestDevice.html">ITestDevice</a></code> to 2246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephensrun tests. This abstraction objectifies the lowest-common-denominator Android device:</p> 2346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<ul> 2446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<li>It has a serial number</li> 2546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<li>It has a state: Online, Available, Recovery, or Not Available</li> 2646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<li>It has some notion of reliability. For instance, if we run a command, we can differentiate 2746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens between the case where the command hasn't finished yet, the case where the device doesn't support 2846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens running commands, and the case where the device has become unresponsive while running the 2946bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens command.</li> 3046bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens</ul> 3146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 3246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<h2>Different Classes of Devices</h2> 3346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<p>The three primary implementations of <code>ITestDevice</code> represent three common 3446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephensusecases.</p> 3546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 3646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<h3>Physical Device</h3> 3746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<p>This is an actual piece of hardware, connected to the TF host machine either by USB, or by using 3846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephensadb's TCP feature. The <a href="/reference/com/android/tradefed/device/TestDevice.html" 3946bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens>TestDevice</a> class sits atop the ddmlib library, which is a Java interface to adb. So any 4046bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephensphysical device listed in <code>adb devices</code> can be instantiated and used as a 4146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<code>TestDevice</code>. 4246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens</p> 4346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 4446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<h3>Emulator</h3> 4546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<p>Emulators are handled specially by TF because they live in another process. To interact with an 4646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari StephensEmulator, specify the <code>--emulator</code> argument for the command. See 4746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<a href="/reference/com/android/tradefed/build/LocalSdkBuildProvider.html" 4846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens>LocalSdkBuildProvider</a> and 4946bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<a href="/reference/com/android/tradefed/targetprep/SdkAvdPreparer.html" 5046bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens>SdkAvdPreparer</a> for more info.</p> 5146bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens 5246bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<h3>No Device</h3> 5346bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<p>Suppose you have a test that doesn't interact with a device at all. For instance, it might just 5446bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephensdownload a file from some service and verify that the file itself is valid. The 5546bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<a href="/reference/com/android/tradefed/device/NullDevice.html" 5646bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens>NullDevice</a> is an <code>ITestDevice</code> that is just a stub. It has a serial number like 5746bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens<code>null-device-N</code>, and most attempted operations either no-op silently or throw. 5846bdf0d2a9fd21d9979fe96f0e98fc1da8243969Omari Stephens</p> 59