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 
17 package com.android.tradefed.device;
18 
19 import com.android.ddmlib.IDevice;
20 import com.android.tradefed.device.IDeviceSelection.BaseDeviceType;
21 import com.android.tradefed.util.ConditionPriorityBlockingQueue.IMatcher;
22 
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Map;
26 
27 /**
28  * Interface for device selection criteria.
29  */
30 public interface IDeviceSelection extends IMatcher<IDevice> {
31 
32     public enum BaseDeviceType {
33         NATIVE_DEVICE,
34         FULL_DEVICE;
35     }
36 
37     /**
38      * Gets a copy of the serial numbers
39      *
40      * @param device The {@link IDevice} representing the device considered for selection.
41      * @return a {@link Collection} of serial numbers
42      */
getSerials(IDevice device)43     public Collection<String> getSerials(IDevice device);
44 
45     /** Returns the list of requested serials. */
getSerials()46     public List<String> getSerials();
47 
48     /**
49      * Gets a copy of the serial numbers exclusion list
50      *
51      * @return a {@link Collection} of serial numbers
52      */
getExcludeSerials()53     public Collection<String> getExcludeSerials();
54 
55     /**
56      * Gets a copy of the product type list
57      *
58      * @return a {@link Collection} of product types
59      */
getProductTypes()60     public Collection<String> getProductTypes();
61 
62     /**
63      * Returns a map of the property list
64      *
65      * @return a {@link Map} of device property names to values
66      */
getProperties()67     public Map<String, String> getProperties();
68 
69     /**
70      * @return <code>true</code> if an emulator has been requested
71      */
emulatorRequested()72     public boolean emulatorRequested();
73 
74     /**
75      * @return <code>true</code> if a device has been requested
76      */
deviceRequested()77     public boolean deviceRequested();
78 
79     /**
80      * @return <code>true</code> if an stub emulator has been requested. A stub emulator is a
81      *         placeholder to be used when config has to launch an emulator.
82      */
stubEmulatorRequested()83     public boolean stubEmulatorRequested();
84 
85     /**
86      * @return <code>true</code> if a null device (aka no device required) has been requested
87      */
nullDeviceRequested()88     public boolean nullDeviceRequested();
89 
90     /**
91      * @return <code>true</code> if a tcp device (aka a adb connected device) has been requested
92      */
93     @Deprecated
tcpDeviceRequested()94     public default boolean tcpDeviceRequested() {
95         return false;
96     }
97 
98     /** @return <code>true</code> if a gce device (aka a remote device) has been requested */
gceDeviceRequested()99     public boolean gceDeviceRequested();
100 
101     /**
102      * Gets the given devices product type
103      *
104      * @param device the {@link IDevice}
105      * @return the device product type or <code>null</code> if unknown
106      */
getDeviceProductType(IDevice device)107     public String getDeviceProductType(IDevice device);
108 
109     /**
110      * Gets the given devices product variant
111      *
112      * @param device the {@link IDevice}
113      * @return the device product variant or <code>null</code> if unknown
114      */
getDeviceProductVariant(IDevice device)115     public String getDeviceProductVariant(IDevice device);
116 
117     /**
118      * Retrieves the battery level for the given device
119      *
120      * @param device the {@link IDevice}
121      * @return the device battery level or <code>null</code> if unknown
122      */
getBatteryLevel(IDevice device)123     public Integer getBatteryLevel(IDevice device);
124 
125     /**
126      * Set the serial numbers inclusion list, replacing any existing values.
127      */
setSerial(String... serialNumber)128     public void setSerial(String... serialNumber);
129 
130     /**
131      * Returns the reason for which the device was not matched.
132      *
133      * @return a Map of serial number to reason for which it wasn't allocated
134      */
getNoMatchReason()135     public Map<String, String> getNoMatchReason();
136 
137     /** Returns the device type we should use. */
getBaseDeviceTypeRequested()138     public BaseDeviceType getBaseDeviceTypeRequested();
139 
140     /** Sets the device type we should use. */
setBaseDeviceTypeRequested(BaseDeviceType type)141     public void setBaseDeviceTypeRequested(BaseDeviceType type);
142 
143     /** Sets whether or not we want to do the battery check. */
setRequireBatteryCheck(boolean requireCheck)144     public void setRequireBatteryCheck(boolean requireCheck);
145 }
146