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 23 /** 24 * A class containing information describing a device under test. 25 */ 26 public class DeviceDescriptor { 27 28 private final String mSerial; 29 private final boolean mIsStubDevice; 30 private final DeviceState mDeviceState; 31 private final DeviceAllocationState mState; 32 private final String mProduct; 33 private final String mProductVariant; 34 private final String mSdkVersion; 35 private final String mBuildId; 36 private final String mBatteryLevel; 37 private final String mDeviceClass; 38 private final String mMacAddress; 39 private final String mSimState; 40 private final String mSimOperator; 41 private final IDevice mIDevice; 42 DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, String product, String productVariant, String sdkVersion, String buildId, String batteryLevel)43 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 44 String product, String productVariant, String sdkVersion, String buildId, 45 String batteryLevel) { 46 this(serial, isStubDevice, state, product, productVariant, sdkVersion, buildId, 47 batteryLevel, "", "", "", ""); 48 } 49 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)50 public DeviceDescriptor(String serial, boolean isStubDevice, DeviceAllocationState state, 51 String product, String productVariant, String sdkVersion, String buildId, 52 String batteryLevel, String deviceClass, String macAddress, String simState, 53 String simOperator) { 54 this( 55 serial, 56 isStubDevice, 57 null, 58 state, 59 product, 60 productVariant, 61 sdkVersion, 62 buildId, 63 batteryLevel, 64 deviceClass, 65 macAddress, 66 simState, 67 simOperator, 68 null); 69 } 70 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)71 public DeviceDescriptor( 72 String serial, 73 boolean isStubDevice, 74 DeviceState deviceState, 75 DeviceAllocationState state, 76 String product, 77 String productVariant, 78 String sdkVersion, 79 String buildId, 80 String batteryLevel, 81 String deviceClass, 82 String macAddress, 83 String simState, 84 String simOperator, 85 IDevice idevice) { 86 mSerial = serial; 87 mIsStubDevice = isStubDevice; 88 mDeviceState = deviceState; 89 mState = state; 90 mProduct = product; 91 mProductVariant = productVariant; 92 mSdkVersion = sdkVersion; 93 mBuildId = buildId; 94 mBatteryLevel = batteryLevel; 95 mDeviceClass = deviceClass; 96 mMacAddress = macAddress; 97 mSimState = simState; 98 mSimOperator = simOperator; 99 mIDevice = idevice; 100 } 101 getSerial()102 public String getSerial() { 103 return mSerial; 104 } 105 isStubDevice()106 public boolean isStubDevice() { 107 return mIsStubDevice; 108 } 109 getDeviceState()110 public DeviceState getDeviceState() { 111 return mDeviceState; 112 } 113 getState()114 public DeviceAllocationState getState() { 115 return mState; 116 } 117 getProduct()118 public String getProduct() { 119 return mProduct; 120 } 121 getProductVariant()122 public String getProductVariant() { 123 return mProductVariant; 124 } 125 getDeviceClass()126 public String getDeviceClass() { 127 return mDeviceClass; 128 } 129 130 /* 131 * This version maps to the ro.build.version.sdk property. 132 */ getSdkVersion()133 public String getSdkVersion() { 134 return mSdkVersion; 135 } 136 getBuildId()137 public String getBuildId() { 138 return mBuildId; 139 } 140 getBatteryLevel()141 public String getBatteryLevel() { 142 return mBatteryLevel; 143 } 144 getMacAddress()145 public String getMacAddress() { 146 return mMacAddress; 147 } 148 getSimState()149 public String getSimState() { 150 return mSimState; 151 } 152 getSimOperator()153 public String getSimOperator() { 154 return mSimOperator; 155 } 156 getProperty(String name)157 public String getProperty(String name) { 158 if (mIDevice == null) { 159 throw new UnsupportedOperationException("this descriptor does not have IDevice"); 160 } 161 return mIDevice.getProperty(name); 162 } 163 164 /** 165 * Provides a description with serials, product and build id 166 */ 167 @Override toString()168 public String toString() { 169 return String.format("[%s %s:%s %s]", mSerial, mProduct, mProductVariant, mBuildId); 170 } 171 } 172