1 /*
2  * Copyright (C) 2011 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 import com.android.ddmlib.AdbCommandRejectedException;
18 import com.android.ddmlib.Client;
19 import com.android.ddmlib.FileListingService;
20 import com.android.ddmlib.IDevice;
21 import com.android.ddmlib.IShellOutputReceiver;
22 import com.android.ddmlib.InstallException;
23 import com.android.ddmlib.InstallReceiver;
24 import com.android.ddmlib.RawImage;
25 import com.android.ddmlib.ScreenRecorderOptions;
26 import com.android.ddmlib.ShellCommandUnresponsiveException;
27 import com.android.ddmlib.SyncException;
28 import com.android.ddmlib.SyncService;
29 import com.android.ddmlib.TimeoutException;
30 import com.android.ddmlib.log.LogReceiver;
31 import com.android.sdklib.AndroidVersion;
32 
33 import com.google.common.util.concurrent.ListenableFuture;
34 import com.google.common.util.concurrent.SettableFuture;
35 
36 import java.io.File;
37 import java.io.IOException;
38 import java.io.Serializable;
39 import java.util.Collections;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.concurrent.Future;
43 import java.util.concurrent.TimeUnit;
44 /** Stub placeholder implementation of a {@link IDevice}. */
45 public class StubDevice implements IDevice, Serializable {
46     private static final long serialVersionUID = 1L;
47     private String mSerial;
48     private final boolean mIsEmulator;
StubDevice(String serial)49     public StubDevice(String serial) {
50         this(serial, false);
51     }
StubDevice(String serial, boolean isEmulator)52     public StubDevice(String serial, boolean isEmulator) {
53         mSerial = serial;
54         mIsEmulator = isEmulator;
55     }
setSerial(String serial)56     public void setSerial(String serial) {
57         mSerial = serial;
58     }
59     /** {@inheritDoc} */
60     @Override
createForward(int localPort, int remotePort)61     public void createForward(int localPort, int remotePort)
62             throws TimeoutException, AdbCommandRejectedException, IOException {
63         throw new IOException("stub");
64     }
65     /** {@inheritDoc} */
66     @Override
createForward( int localPort, String remoteSocketName, DeviceUnixSocketNamespace namespace)67     public void createForward(
68             int localPort, String remoteSocketName, DeviceUnixSocketNamespace namespace)
69             throws TimeoutException, AdbCommandRejectedException, IOException {
70         // ignore
71     }
72     /** {@inheritDoc} */
73     @Override
getAvdName()74     public String getAvdName() {
75         return null;
76     }
77     /** {@inheritDoc} */
78     @Override
getAvdPath()79     public String getAvdPath() {
80         return null;
81     }
82     /** {@inheritDoc} */
83     @Override
getClient(String applicationName)84     public Client getClient(String applicationName) {
85         return null;
86     }
87     /** {@inheritDoc} */
88     @Override
getClientName(int pid)89     public String getClientName(int pid) {
90         return null;
91     }
92     /** {@inheritDoc} */
93     @Override
getClients()94     public Client[] getClients() {
95         return null;
96     }
97     /** {@inheritDoc} */
98     @Override
getFileListingService()99     public FileListingService getFileListingService() {
100         return null;
101     }
102     /** {@inheritDoc} */
103     @Override
getMountPoint(String name)104     public String getMountPoint(String name) {
105         return null;
106     }
107     /**
108      * {@inheritDoc}
109      *
110      * @deprecated use {@link #getSystemProperty(String)} instead.
111      */
112     @Override
113     @Deprecated
getProperties()114     public Map<String, String> getProperties() {
115         return null;
116     }
117     /** {@inheritDoc} */
118     @Override
getProperty(String name)119     public String getProperty(String name) {
120         return null;
121     }
122     /**
123      * {@inheritDoc}
124      *
125      * @deprecated deprecated in ddmlib with "implementation detail" as reason.
126      */
127     @Override
128     @Deprecated
getPropertyCount()129     public int getPropertyCount() {
130         return 0;
131     }
132     /** {@inheritDoc} */
133     @Override
getScreenshot()134     public RawImage getScreenshot()
135             throws TimeoutException, AdbCommandRejectedException, IOException {
136         throw new IOException("stub");
137     }
138     /* (not javadoc)
139      * The parent method has no javadoc, so it's invalid for us to attempt to inherit
140      */
141     @Override
getScreenshot(long timeout, TimeUnit unit)142     public RawImage getScreenshot(long timeout, TimeUnit unit)
143             throws TimeoutException, AdbCommandRejectedException, IOException {
144         throw new IOException("stub");
145     }
146     /** {@inheritDoc} */
147     @Override
getSerialNumber()148     public String getSerialNumber() {
149         return mSerial;
150     }
151     /** {@inheritDoc} */
152     @Override
getState()153     public DeviceState getState() {
154         return DeviceState.OFFLINE;
155     }
156     /** {@inheritDoc} */
157     @Override
getSyncService()158     public SyncService getSyncService()
159             throws TimeoutException, AdbCommandRejectedException, IOException {
160         throw new IOException("stub");
161     }
162     /** {@inheritDoc} */
163     @Override
hasClients()164     public boolean hasClients() {
165         return false;
166     }
167     /** {@inheritDoc} */
168     @Override
installPackage(String packageFilePath, boolean reinstall, String... extraArgs)169     public void installPackage(String packageFilePath, boolean reinstall, String... extraArgs)
170             throws InstallException {
171         throw new InstallException(new IOException("stub"));
172     }
173     /** {@inheritDoc} */
174     @Override
installPackage( String packageFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)175     public void installPackage(
176             String packageFilePath,
177             boolean reinstall,
178             InstallReceiver receiver,
179             String... extraArgs)
180             throws InstallException {
181         throw new InstallException(new IOException("stub"));
182     }
183     /** {@inheritDoc} */
184     @Override
installPackage( String packageFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)185     public void installPackage(
186             String packageFilePath,
187             boolean reinstall,
188             InstallReceiver receiver,
189             long maxTimeout,
190             long maxTimeToOutputResponse,
191             TimeUnit maxTimeUnits,
192             String... extraArgs)
193             throws InstallException {
194         throw new InstallException(new IOException("stub"));
195     }
196     /** {@inheritDoc} */
197     @Override
installPackages( List<File> apkFilePaths, boolean reinstall, List<String> extraArgs, long timeOutInMs, TimeUnit timeunit)198     public void installPackages(
199             List<File> apkFilePaths,
200             boolean reinstall,
201             List<String> extraArgs,
202             long timeOutInMs,
203             TimeUnit timeunit)
204             throws InstallException {
205         throw new InstallException(new IOException("stub"));
206     }
207     /** {@inheritDoc} */
208     @Override
uninstallApp(String applicationID, String... extraArgs)209     public String uninstallApp(String applicationID, String... extraArgs) throws InstallException {
210         throw new InstallException(new IOException("stub"));
211     }
212     /** {@inheritDoc} */
213     @Override
installRemotePackage(String remoteFilePath, boolean reinstall, String... extraArgs)214     public void installRemotePackage(String remoteFilePath, boolean reinstall, String... extraArgs)
215             throws InstallException {
216         throw new InstallException(new IOException("stub"));
217     }
218     /** {@inheritDoc} */
219     @Override
installRemotePackage( String remoteFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)220     public void installRemotePackage(
221             String remoteFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)
222             throws InstallException {
223         throw new InstallException(new IOException("stub"));
224     }
225     /** {@inheritDoc} */
226     @Override
installRemotePackage( String remoteFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)227     public void installRemotePackage(
228             String remoteFilePath,
229             boolean reinstall,
230             InstallReceiver receiver,
231             long maxTimeout,
232             long maxTimeToOutputResponse,
233             TimeUnit maxTimeUnits,
234             String... extraArgs)
235             throws InstallException {
236         throw new InstallException(new IOException("stub"));
237     }
238     /** {@inheritDoc} */
239     @Override
isBootLoader()240     public boolean isBootLoader() {
241         return false;
242     }
243     /** {@inheritDoc} */
244     @Override
isEmulator()245     public boolean isEmulator() {
246         return mIsEmulator;
247     }
248     /** {@inheritDoc} */
249     @Override
isOffline()250     public boolean isOffline() {
251         return true;
252     }
253     /** {@inheritDoc} */
254     @Override
isOnline()255     public boolean isOnline() {
256         return false;
257     }
258     /** {@inheritDoc} */
259     @Override
reboot(String into)260     public void reboot(String into)
261             throws TimeoutException, AdbCommandRejectedException, IOException {
262         throw new IOException("stub");
263     }
264     /** {@inheritDoc} */
265     @Override
removeForward(int localPort, int remotePort)266     public void removeForward(int localPort, int remotePort)
267             throws TimeoutException, AdbCommandRejectedException, IOException {
268         throw new IOException("stub");
269     }
270     /** {@inheritDoc} */
271     @Override
removeForward( int localPort, String remoteSocketName, DeviceUnixSocketNamespace namespace)272     public void removeForward(
273             int localPort, String remoteSocketName, DeviceUnixSocketNamespace namespace)
274             throws TimeoutException, AdbCommandRejectedException, IOException {
275         throw new IOException("stub");
276     }
277     /** {@inheritDoc} */
278     @Override
removeForward(int localPort)279     public void removeForward(int localPort)
280             throws TimeoutException, AdbCommandRejectedException, IOException {
281         throw new IOException("stub");
282     }
283     /** {@inheritDoc} */
284     @Override
createReverse(int remotePort, int localPort)285     public void createReverse(int remotePort, int localPort)
286             throws TimeoutException, AdbCommandRejectedException, IOException {
287         throw new IOException("stub");
288     }
289     /** {@inheritDoc} */
290     @Override
removeReverse(int remotePort)291     public void removeReverse(int remotePort)
292             throws TimeoutException, AdbCommandRejectedException, IOException {
293         throw new IOException("stub");
294     }
295     /** {@inheritDoc} */
296     @Override
removeRemotePackage(String remoteFilePath)297     public void removeRemotePackage(String remoteFilePath) throws InstallException {
298         throw new InstallException(new IOException("stub"));
299     }
300     /** {@inheritDoc} */
301     @Override
runEventLogService(LogReceiver receiver)302     public void runEventLogService(LogReceiver receiver)
303             throws TimeoutException, AdbCommandRejectedException, IOException {
304         throw new IOException("stub");
305     }
306     /** {@inheritDoc} */
307     @Override
runLogService(String logname, LogReceiver receiver)308     public void runLogService(String logname, LogReceiver receiver)
309             throws TimeoutException, AdbCommandRejectedException, IOException {
310         throw new IOException("stub");
311     }
312     /** {@inheritDoc} */
313     @Override
syncPackageToDevice(String localFilePath)314     public String syncPackageToDevice(String localFilePath)
315             throws TimeoutException, AdbCommandRejectedException, IOException, SyncException {
316         throw new IOException("stub");
317     }
318     /** {@inheritDoc} */
319     @Override
uninstallPackage(String packageName)320     public String uninstallPackage(String packageName) throws InstallException {
321         throw new InstallException(new IOException("stub"));
322     }
323     /** {@inheritDoc} */
324     @Override
pushFile(String local, String remote)325     public void pushFile(String local, String remote)
326             throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
327         // ignore
328     }
329     /** {@inheritDoc} */
330     @Override
pullFile(String remote, String local)331     public void pullFile(String remote, String local)
332             throws IOException, AdbCommandRejectedException, TimeoutException, SyncException {
333         // ignore
334     }
335     /**
336      * {@inheritDoc}
337      *
338      * @deprecated use {@link #getProperty(String)} instead.
339      */
340     @Override
341     @Deprecated
getPropertySync(String name)342     public String getPropertySync(String name)
343             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
344                     IOException {
345         return null;
346     }
347     /** {@inheritDoc} */
348     @Override
arePropertiesSet()349     public boolean arePropertiesSet() {
350         return false;
351     }
352     /**
353      * {@inheritDoc}
354      *
355      * @deprecated use {@link #getProperty(String)} instead.
356      */
357     @Override
358     @Deprecated
getPropertyCacheOrSync(String name)359     public String getPropertyCacheOrSync(String name)
360             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
361                     IOException {
362         return null;
363     }
364     /**
365      * {@inheritDoc}
366      *
367      * @deprecated use {@link #getBattery()} instead.
368      */
369     @Override
370     @Deprecated
getBatteryLevel()371     public Integer getBatteryLevel()
372             throws TimeoutException, AdbCommandRejectedException, IOException,
373                     ShellCommandUnresponsiveException {
374         return null;
375     }
376     /**
377      * {@inheritDoc}
378      *
379      * @deprecated use {@link #getBattery(long, TimeUnit)} instead.
380      */
381     @Override
382     @Deprecated
getBatteryLevel(long freshnessMs)383     public Integer getBatteryLevel(long freshnessMs)
384             throws TimeoutException, AdbCommandRejectedException, IOException,
385                     ShellCommandUnresponsiveException {
386         return null;
387     }
388     /** {@inheritDoc} */
389     @Override
getName()390     public String getName() {
391         return null;
392     }
393     /** {@inheritDoc} */
394     @Override
executeShellCommand( String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)395     public void executeShellCommand(
396             String command,
397             IShellOutputReceiver receiver,
398             long maxTimeToOutputResponse,
399             TimeUnit maxTimeUnits)
400             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
401                     IOException {
402         throw new IOException("stub");
403     }
404     /** {@inheritDoc} */
405     @Override
executeShellCommand( String command, IShellOutputReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)406     public void executeShellCommand(
407             String command,
408             IShellOutputReceiver receiver,
409             long maxTimeout,
410             long maxTimeToOutputResponse,
411             TimeUnit maxTimeUnits)
412             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
413                     IOException {
414         throw new IOException("stub");
415     }
416     /** {@inheritDoc} */
417     @Override
executeShellCommand(String command, IShellOutputReceiver receiver)418     public void executeShellCommand(String command, IShellOutputReceiver receiver)
419             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
420                     IOException {
421         throw new IOException("stub");
422     }
423     /**
424      * {@inheritDoc}
425      *
426      * @deprecated use {@link #executeShellCommand(String, IShellOutputReceiver, long, TimeUnit)}.
427      */
428     @Deprecated
429     @Override
executeShellCommand( String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)430     public void executeShellCommand(
431             String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)
432             throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
433                     IOException {
434         throw new IOException("stub");
435     }
436     /** {@inheritDoc} */
437     @Override
supportsFeature(Feature feature)438     public boolean supportsFeature(Feature feature) {
439         return false;
440     }
441     /* (non-Javadoc)
442      * @see com.android.ddmlib.IDevice#supportsFeature(com.android.ddmlib.IDevice.HardwareFeature)
443      */
444     @Override
supportsFeature(HardwareFeature arg0)445     public boolean supportsFeature(HardwareFeature arg0) {
446         return true;
447     }
448     /** {@inheritDoc} */
449     @Override
startScreenRecorder( String remoteFilePath, ScreenRecorderOptions options, IShellOutputReceiver receiver)450     public void startScreenRecorder(
451             String remoteFilePath, ScreenRecorderOptions options, IShellOutputReceiver receiver)
452             throws TimeoutException, AdbCommandRejectedException, IOException,
453                     ShellCommandUnresponsiveException {
454         // no-op
455     }
456     /** {@inheritDoc} */
457     @Override
getSystemProperty(String name)458     public ListenableFuture<String> getSystemProperty(String name) {
459         SettableFuture<String> f = SettableFuture.create();
460         f.set(null);
461         return f;
462     }
463     /** {@inheritDoc} */
464     @Override
getBattery()465     public Future<Integer> getBattery() {
466         SettableFuture<Integer> f = SettableFuture.create();
467         f.set(0);
468         return f;
469     }
470     /** {@inheritDoc} */
471     @Override
getBattery(long freshnessTime, TimeUnit timeUnit)472     public Future<Integer> getBattery(long freshnessTime, TimeUnit timeUnit) {
473         return getBattery();
474     }
475     /** {@inheritDoc} */
476     @Override
getAbis()477     public List<String> getAbis() {
478         return Collections.emptyList();
479     }
480     /** {@inheritDoc} */
481     @Override
getDensity()482     public int getDensity() {
483         return 0;
484     }
485     /** {@inheritDoc} */
486     @Override
getLanguage()487     public String getLanguage() {
488         return null;
489     }
490     /** {@inheritDoc} */
491     @Override
getRegion()492     public String getRegion() {
493         return null;
494     }
495     /** {@inheritDoc} */
496     @Override
getVersion()497     public AndroidVersion getVersion() {
498         return null;
499     }
500     /** {@inheritDoc} */
501     @Override
isRoot()502     public boolean isRoot()
503             throws TimeoutException, AdbCommandRejectedException, IOException,
504                     ShellCommandUnresponsiveException {
505         throw new IOException("stub");
506     }
507     /** {@inheritDoc} */
508     @Override
root()509     public boolean root()
510             throws TimeoutException, AdbCommandRejectedException, IOException,
511                     ShellCommandUnresponsiveException {
512         throw new IOException("stub");
513     }
514 }
515