1 /*
2  * Copyright (C) 2010 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.IDevice;
19 
20 /**
21  * A ITestDevice whose lifecycle is managed.
22  */
23 public interface IManagedTestDevice extends ITestDevice {
24 
25     /**
26      * Container for a response to a {@link IManagedTestDevice#handleAllocationEvent(DeviceEvent)}
27      * call
28      */
29     static class DeviceEventResponse {
30         /** the new state of the device */
31         final DeviceAllocationState allocationState;
32         /** true if state changed as a result of device event */
33         final boolean stateChanged;
34 
DeviceEventResponse(DeviceAllocationState s, boolean b)35         DeviceEventResponse(DeviceAllocationState s, boolean b) {
36             allocationState = s;
37             stateChanged = b;
38         }
39     }
40 
41     /**
42      * Update the IDevice associated with this ITestDevice.
43      * <p/>
44      * The new IDevice must refer the same physical device as the current reference. This method
45      * will be called if DDMS has allocated a new IDevice
46      *
47      * @param device the {@link IDevice}
48      */
setIDevice(IDevice device)49     public void setIDevice(IDevice device);
50 
51     /**
52      * Update the device's state.
53      *
54      * @param deviceState the {@link TestDeviceState}
55      */
setDeviceState(TestDeviceState deviceState)56     public void setDeviceState(TestDeviceState deviceState);
57 
58     /**
59      * Set the fastboot option for the device. Should be set when device is first
60      * allocated.
61      *
62      * @param fastbootEnabled whether fastboot is available for the device or not
63      */
setFastbootEnabled(boolean fastbootEnabled)64     public void setFastbootEnabled(boolean fastbootEnabled);
65 
66     /**
67      * Return if fastboot is available for the device.
68      */
isFastbootEnabled()69     public boolean isFastbootEnabled();
70 
71     /**
72      * Sets the path to the fastboot binary that should be used.
73      * Still requires {@link #isFastbootEnabled()} to be true, to have fastboot functions enabled.
74      */
setFastbootPath(String fastbootPath)75     public void setFastbootPath(String fastbootPath);
76 
77     /**
78      * Returns the path of the fastboot binary being used.
79      * Still requires {@link #isFastbootEnabled()} to be true, to have fastboot functions enabled.
80      */
getFastbootPath()81     public String getFastbootPath();
82 
83     /**
84      * Returns the version string of the fastboot binary being used. Or null if something goes
85      * wrong.
86      */
getFastbootVersion()87     public String getFastbootVersion();
88 
89     /**
90      * Invoke recovery on the device.
91      *
92      * @throws DeviceNotAvailableException if recovery was not successful
93      * @return True if recovery attempted and successful, returns False if recovery was skipped
94      */
recoverDevice()95     public boolean recoverDevice() throws DeviceNotAvailableException;
96 
97     /**
98      * Sets the {@link Process}, when this device is an emulator.
99      */
setEmulatorProcess(Process p)100     public void setEmulatorProcess(Process p);
101 
102     /**
103      * Return the {@link Process} corresponding to this emulator.
104      *
105      * @return the {@link Process} or <code>null</code>
106      */
getEmulatorProcess()107     public Process getEmulatorProcess();
108 
109     /**
110      * Return the current allocation state of device
111      */
getAllocationState()112     public DeviceAllocationState getAllocationState();
113 
114     /**
115      * Process the given {@link com.android.tradefed.device.DeviceEvent}. May transition device
116      * to new state. Will inform the {@link IDeviceMonitor} of any state transitions.
117      */
handleAllocationEvent(DeviceEvent event)118     public DeviceEventResponse handleAllocationEvent(DeviceEvent event);
119 
120     /**
121      * Return the {@link IDeviceStateMonitor} associated with device.
122      */
getMonitor()123     public IDeviceStateMonitor getMonitor();
124 
125     /**
126      * Returns the MAC address of the device, null if it fails to query from the device.
127      */
getMacAddress()128     public String getMacAddress();
129 
130     /** Return the SIM card state or null if not available or device is not available. */
getSimState()131     public String getSimState();
132 
133     /** Return the SIM card operator or null if not available or if device is not available. */
getSimOperator()134     public String getSimOperator();
135 }
136