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 mHardwareRevision; 41 private final String mBatteryLevel; 42 private final String mDeviceClass; 43 private final String mMacAddress; 44 private final String mSimState; 45 private final String mSimOperator; 46 private final IDevice mIDevice; 47 private final boolean mIsTemporary; 48 private final String mPreconfiguredIp; 49 private final Integer mPreconfiguredDeviceNumOffset; 50 DeviceDescriptor()51 public DeviceDescriptor() { 52 this(null, false, null, null, null, null, null, null); 53 } 54 DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel)55 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 56 String product, String productVariant, String sdkVersion, String buildId, 57 String batteryLevel) { 58 this(serial, isStubDevice, state, product, productVariant, sdkVersion, buildId, 59 batteryLevel, "", "", "", ""); 60 } 61 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)62 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 63 String product, String productVariant, String sdkVersion, String buildId, 64 String batteryLevel, String deviceClass, String macAddress, String simState, 65 String simOperator) { 66 this( 67 serial, 68 null, 69 isStubDevice, 70 null, 71 state, 72 null, 73 product, 74 productVariant, 75 sdkVersion, 76 buildId, 77 null, 78 batteryLevel, 79 deviceClass, 80 macAddress, 81 simState, 82 simOperator, 83 false, 84 null, 85 null, 86 null); 87 } 88 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)89 public DeviceDescriptor( 90 String serial, 91 boolean isStubDevice, 92 DeviceAllocationState state, 93 String product, 94 String productVariant, 95 String sdkVersion, 96 String buildId, 97 String batteryLevel, 98 String deviceClass, 99 String macAddress, 100 String simState, 101 String simOperator, 102 IDevice idevice) { 103 this( 104 serial, 105 null, 106 isStubDevice, 107 null, 108 state, 109 null, 110 product, 111 productVariant, 112 sdkVersion, 113 buildId, 114 null, 115 batteryLevel, 116 deviceClass, 117 macAddress, 118 simState, 119 simOperator, 120 false, 121 null, 122 null, 123 idevice); 124 } 125 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)126 public DeviceDescriptor( 127 String serial, 128 boolean isStubDevice, 129 DeviceState deviceState, 130 DeviceAllocationState state, 131 String product, 132 String productVariant, 133 String sdkVersion, 134 String buildId, 135 String batteryLevel, 136 String deviceClass, 137 String macAddress, 138 String simState, 139 String simOperator, 140 IDevice idevice) { 141 this( 142 serial, 143 null, 144 isStubDevice, 145 deviceState, 146 state, 147 null, 148 product, 149 productVariant, 150 sdkVersion, 151 buildId, 152 null, 153 batteryLevel, 154 deviceClass, 155 macAddress, 156 simState, 157 simOperator, 158 false, 159 null, 160 null, 161 idevice); 162 } 163 DeviceDescriptor( String serial, String displaySerial, boolean isStubDevice, DeviceState deviceState, DeviceAllocationState state, TestDeviceState testDeviceState, String product, String productVariant, String sdkVersion, String buildId, String hardwareRevision, String batteryLevel, String deviceClass, String macAddress, String simState, String simOperator, boolean isTemporary, String preconfiguredIp, Integer preconfiguredDeviceNumOffset, IDevice idevice)164 public DeviceDescriptor( 165 String serial, 166 String displaySerial, 167 boolean isStubDevice, 168 DeviceState deviceState, 169 DeviceAllocationState state, 170 TestDeviceState testDeviceState, 171 String product, 172 String productVariant, 173 String sdkVersion, 174 String buildId, 175 String hardwareRevision, 176 String batteryLevel, 177 String deviceClass, 178 String macAddress, 179 String simState, 180 String simOperator, 181 boolean isTemporary, 182 String preconfiguredIp, 183 Integer preconfiguredDeviceNumOffset, 184 IDevice idevice) { 185 mSerial = serial; 186 mDisplaySerial = displaySerial; 187 mIsStubDevice = isStubDevice; 188 mDeviceState = deviceState; 189 mTestDeviceState = testDeviceState; 190 mState = state; 191 mProduct = product; 192 mProductVariant = productVariant; 193 mSdkVersion = sdkVersion; 194 mBuildId = buildId; 195 mHardwareRevision = hardwareRevision; 196 mBatteryLevel = batteryLevel; 197 mDeviceClass = deviceClass; 198 mMacAddress = macAddress; 199 mSimState = simState; 200 mSimOperator = simOperator; 201 mIsTemporary = isTemporary; 202 mPreconfiguredIp = preconfiguredIp; 203 mPreconfiguredDeviceNumOffset = preconfiguredDeviceNumOffset; 204 mIDevice = idevice; 205 } 206 207 /** Used for easy state updating in ClusterDeviceMonitor. */ DeviceDescriptor(DeviceDescriptor d, DeviceAllocationState state)208 public DeviceDescriptor(DeviceDescriptor d, DeviceAllocationState state) { 209 this( 210 d.getSerial(), 211 d.getDisplaySerial(), 212 d.isStubDevice(), 213 d.getDeviceState(), 214 state, 215 d.getTestDeviceState(), 216 d.getProduct(), 217 d.getProductVariant(), 218 d.getSdkVersion(), 219 d.getBuildId(), 220 null, 221 d.getBatteryLevel(), 222 d.getDeviceClass(), 223 d.getMacAddress(), 224 d.getSimState(), 225 d.getSimOperator(), 226 d.isTemporary(), 227 d.getPreconfiguredIp(), 228 d.getPreconfiguredDeviceNumOffset(), 229 d.getIDevice()); 230 } 231 232 /** Used for easy state updating of serial for placeholder devices. */ DeviceDescriptor(DeviceDescriptor d, String serial, String displaySerial)233 public DeviceDescriptor(DeviceDescriptor d, String serial, String displaySerial) { 234 this( 235 serial, 236 displaySerial, 237 d.isStubDevice(), 238 d.getDeviceState(), 239 d.getState(), 240 d.getTestDeviceState(), 241 d.getProduct(), 242 d.getProductVariant(), 243 d.getSdkVersion(), 244 d.getBuildId(), 245 null, 246 d.getBatteryLevel(), 247 d.getDeviceClass(), 248 d.getMacAddress(), 249 d.getSimState(), 250 d.getSimOperator(), 251 d.isTemporary(), 252 d.getPreconfiguredIp(), 253 d.getPreconfiguredDeviceNumOffset(), 254 d.getIDevice()); 255 } 256 DeviceDescriptor( DeviceDescriptor d, String preconfiguredIp, Integer preconfiguredDeviceNumOffset)257 public DeviceDescriptor( 258 DeviceDescriptor d, String preconfiguredIp, Integer preconfiguredDeviceNumOffset) { 259 this( 260 d.getSerial(), 261 d.getDisplaySerial(), 262 d.isStubDevice(), 263 d.getDeviceState(), 264 d.getState(), 265 d.getTestDeviceState(), 266 d.getProduct(), 267 d.getProductVariant(), 268 d.getSdkVersion(), 269 d.getBuildId(), 270 null, 271 d.getBatteryLevel(), 272 d.getDeviceClass(), 273 d.getMacAddress(), 274 d.getSimState(), 275 d.getSimOperator(), 276 d.isTemporary(), 277 preconfiguredIp, 278 preconfiguredDeviceNumOffset, 279 d.getIDevice()); 280 } 281 getSerial()282 public String getSerial() { 283 return mSerial; 284 } 285 getDisplaySerial()286 public String getDisplaySerial() { 287 return mDisplaySerial; 288 } 289 isStubDevice()290 public boolean isStubDevice() { 291 return mIsStubDevice; 292 } 293 getDeviceState()294 public DeviceState getDeviceState() { 295 return mDeviceState; 296 } 297 getState()298 public DeviceAllocationState getState() { 299 return mState; 300 } 301 getTestDeviceState()302 public TestDeviceState getTestDeviceState() { 303 return mTestDeviceState; 304 } 305 getProduct()306 public String getProduct() { 307 return mProduct; 308 } 309 getProductVariant()310 public String getProductVariant() { 311 return mProductVariant; 312 } 313 getDeviceClass()314 public String getDeviceClass() { 315 return mDeviceClass; 316 } 317 318 /* 319 * This version maps to the ro.build.version.sdk property. 320 */ getSdkVersion()321 public String getSdkVersion() { 322 return mSdkVersion; 323 } 324 getBuildId()325 public String getBuildId() { 326 return mBuildId; 327 } 328 getHardwareRevision()329 public String getHardwareRevision() { 330 return mHardwareRevision; 331 } 332 getBatteryLevel()333 public String getBatteryLevel() { 334 return mBatteryLevel; 335 } 336 getMacAddress()337 public String getMacAddress() { 338 return mMacAddress; 339 } 340 getSimState()341 public String getSimState() { 342 return mSimState; 343 } 344 getSimOperator()345 public String getSimOperator() { 346 return mSimOperator; 347 } 348 349 /** Returns whether or not the device will be deleted at the end of the invocation. */ isTemporary()350 public boolean isTemporary() { 351 return mIsTemporary; 352 } 353 getPreconfiguredIp()354 public String getPreconfiguredIp() { 355 return mPreconfiguredIp; 356 } 357 getPreconfiguredDeviceNumOffset()358 public Integer getPreconfiguredDeviceNumOffset() { 359 return mPreconfiguredDeviceNumOffset; 360 } 361 getIDevice()362 private IDevice getIDevice() { 363 return mIDevice; 364 } 365 getProperty(String name)366 public String getProperty(String name) { 367 if (mIDevice == null) { 368 throw new UnsupportedOperationException("this descriptor does not have IDevice"); 369 } 370 return mIDevice.getProperty(name); 371 } 372 373 /** 374 * Provides a description with serials, product and build id 375 */ 376 @Override toString()377 public String toString() { 378 return String.format("[%s %s:%s %s]", mSerial, mProduct, mProductVariant, mBuildId); 379 } 380 } 381