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