1 /* 2 * Copyright (C) 2013 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.command.remote; 18 19 import com.android.ddmlib.IDevice; 20 import com.android.ddmlib.IDevice.DeviceState; 21 import com.android.tradefed.device.DeviceAllocationState; 22 import com.android.tradefed.device.TestDeviceState; 23 24 import java.io.Serializable; 25 26 /** A class containing information describing a device under test. */ 27 public class DeviceDescriptor implements Serializable { 28 private static final long serialVersionUID = 1L; 29 30 private final String mSerial; 31 private final String mDisplaySerial; 32 private final boolean mIsStubDevice; 33 private final DeviceState mDeviceState; // Ddmlib updated state. 34 private final DeviceAllocationState mState; 35 private final TestDeviceState mTestDeviceState; // Tradefed updated state. 36 private final String mProduct; 37 private final String mProductVariant; 38 private final String mSdkVersion; 39 private final String mBuildId; 40 private final String mBatteryLevel; 41 private final String mDeviceClass; 42 private final String mMacAddress; 43 private final String mSimState; 44 private final String mSimOperator; 45 private final IDevice mIDevice; 46 private final boolean mIsTemporary; 47 DeviceDescriptor()48 public DeviceDescriptor() { 49 this(null, false, null, null, null, null, null, null); 50 } 51 DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel)52 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 53 String product, String productVariant, String sdkVersion, String buildId, 54 String batteryLevel) { 55 this(serial, isStubDevice, state, product, productVariant, sdkVersion, buildId, 56 batteryLevel, "", "", "", ""); 57 } 58 DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel, String deviceClass, String macAddress, String simState, String simOperator)59 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 60 String product, String productVariant, String sdkVersion, String buildId, 61 String batteryLevel, String deviceClass, String macAddress, String simState, 62 String simOperator) { 63 this( 64 serial, 65 null, 66 isStubDevice, 67 null, 68 state, 69 null, 70 product, 71 productVariant, 72 sdkVersion, 73 buildId, 74 batteryLevel, 75 deviceClass, 76 macAddress, 77 simState, 78 simOperator, 79 false, 80 null); 81 } 82 DeviceDescriptor( String serial, boolean isStubDevice, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel, String deviceClass, String macAddress, String simState, String simOperator, IDevice idevice)83 public DeviceDescriptor( 84 String serial, 85 boolean isStubDevice, 86 DeviceAllocationState state, 87 String product, 88 String productVariant, 89 String sdkVersion, 90 String buildId, 91 String batteryLevel, 92 String deviceClass, 93 String macAddress, 94 String simState, 95 String simOperator, 96 IDevice idevice) { 97 this( 98 serial, 99 null, 100 isStubDevice, 101 null, 102 state, 103 null, 104 product, 105 productVariant, 106 sdkVersion, 107 buildId, 108 batteryLevel, 109 deviceClass, 110 macAddress, 111 simState, 112 simOperator, 113 false, 114 idevice); 115 } 116 DeviceDescriptor( String serial, boolean isStubDevice, DeviceState deviceState, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel, String deviceClass, String macAddress, String simState, String simOperator, IDevice idevice)117 public DeviceDescriptor( 118 String serial, 119 boolean isStubDevice, 120 DeviceState deviceState, 121 DeviceAllocationState state, 122 String product, 123 String productVariant, 124 String sdkVersion, 125 String buildId, 126 String batteryLevel, 127 String deviceClass, 128 String macAddress, 129 String simState, 130 String simOperator, 131 IDevice idevice) { 132 this( 133 serial, 134 null, 135 isStubDevice, 136 deviceState, 137 state, 138 null, 139 product, 140 productVariant, 141 sdkVersion, 142 buildId, 143 batteryLevel, 144 deviceClass, 145 macAddress, 146 simState, 147 simOperator, 148 false, 149 idevice); 150 } 151 DeviceDescriptor( String serial, String displaySerial, boolean isStubDevice, DeviceState deviceState, DeviceAllocationState state, TestDeviceState testDeviceState, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel, String deviceClass, String macAddress, String simState, String simOperator, boolean isTemporary, IDevice idevice)152 public DeviceDescriptor( 153 String serial, 154 String displaySerial, 155 boolean isStubDevice, 156 DeviceState deviceState, 157 DeviceAllocationState state, 158 TestDeviceState testDeviceState, 159 String product, 160 String productVariant, 161 String sdkVersion, 162 String buildId, 163 String batteryLevel, 164 String deviceClass, 165 String macAddress, 166 String simState, 167 String simOperator, 168 boolean isTemporary, 169 IDevice idevice) { 170 mSerial = serial; 171 mDisplaySerial = displaySerial; 172 mIsStubDevice = isStubDevice; 173 mDeviceState = deviceState; 174 mTestDeviceState = testDeviceState; 175 mState = state; 176 mProduct = product; 177 mProductVariant = productVariant; 178 mSdkVersion = sdkVersion; 179 mBuildId = buildId; 180 mBatteryLevel = batteryLevel; 181 mDeviceClass = deviceClass; 182 mMacAddress = macAddress; 183 mSimState = simState; 184 mSimOperator = simOperator; 185 mIsTemporary = isTemporary; 186 mIDevice = idevice; 187 } 188 189 /** Used for easy state updating in ClusterDeviceMonitor. */ DeviceDescriptor(DeviceDescriptor d, DeviceAllocationState state)190 public DeviceDescriptor(DeviceDescriptor d, DeviceAllocationState state) { 191 this( 192 d.getSerial(), 193 d.getDisplaySerial(), 194 d.isStubDevice(), 195 d.getDeviceState(), 196 state, 197 d.getTestDeviceState(), 198 d.getProduct(), 199 d.getProductVariant(), 200 d.getSdkVersion(), 201 d.getBuildId(), 202 d.getBatteryLevel(), 203 d.getDeviceClass(), 204 d.getMacAddress(), 205 d.getSimState(), 206 d.getSimOperator(), 207 d.isTemporary(), 208 d.getIDevice()); 209 } 210 211 /** Used for easy state updating of serial for placeholder devices. */ DeviceDescriptor(DeviceDescriptor d, String serial, String displaySerial)212 public DeviceDescriptor(DeviceDescriptor d, String serial, String displaySerial) { 213 this( 214 serial, 215 displaySerial, 216 d.isStubDevice(), 217 d.getDeviceState(), 218 d.getState(), 219 d.getTestDeviceState(), 220 d.getProduct(), 221 d.getProductVariant(), 222 d.getSdkVersion(), 223 d.getBuildId(), 224 d.getBatteryLevel(), 225 d.getDeviceClass(), 226 d.getMacAddress(), 227 d.getSimState(), 228 d.getSimOperator(), 229 d.isTemporary(), 230 d.getIDevice()); 231 } 232 getSerial()233 public String getSerial() { 234 return mSerial; 235 } 236 getDisplaySerial()237 public String getDisplaySerial() { 238 return mDisplaySerial; 239 } 240 isStubDevice()241 public boolean isStubDevice() { 242 return mIsStubDevice; 243 } 244 getDeviceState()245 public DeviceState getDeviceState() { 246 return mDeviceState; 247 } 248 getState()249 public DeviceAllocationState getState() { 250 return mState; 251 } 252 getTestDeviceState()253 public TestDeviceState getTestDeviceState() { 254 return mTestDeviceState; 255 } 256 getProduct()257 public String getProduct() { 258 return mProduct; 259 } 260 getProductVariant()261 public String getProductVariant() { 262 return mProductVariant; 263 } 264 getDeviceClass()265 public String getDeviceClass() { 266 return mDeviceClass; 267 } 268 269 /* 270 * This version maps to the ro.build.version.sdk property. 271 */ getSdkVersion()272 public String getSdkVersion() { 273 return mSdkVersion; 274 } 275 getBuildId()276 public String getBuildId() { 277 return mBuildId; 278 } 279 getBatteryLevel()280 public String getBatteryLevel() { 281 return mBatteryLevel; 282 } 283 getMacAddress()284 public String getMacAddress() { 285 return mMacAddress; 286 } 287 getSimState()288 public String getSimState() { 289 return mSimState; 290 } 291 getSimOperator()292 public String getSimOperator() { 293 return mSimOperator; 294 } 295 296 /** Returns whether or not the device will be deleted at the end of the invocation. */ isTemporary()297 public boolean isTemporary() { 298 return mIsTemporary; 299 } 300 getIDevice()301 private IDevice getIDevice() { 302 return mIDevice; 303 } 304 getProperty(String name)305 public String getProperty(String name) { 306 if (mIDevice == null) { 307 throw new UnsupportedOperationException("this descriptor does not have IDevice"); 308 } 309 return mIDevice.getProperty(name); 310 } 311 312 /** 313 * Provides a description with serials, product and build id 314 */ 315 @Override toString()316 public String toString() { 317 return String.format("[%s %s:%s %s]", mSerial, mProduct, mProductVariant, mBuildId); 318 } 319 } 320