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