FileDocCategorySizeDatePackage
Device.javaAPI DocAndroid 1.5 API10178Wed May 06 22:41:08 BST 2009com.android.ddmlib

Device

public final class Device extends Object implements IDevice
A Device. It can be a physical device or an emulator. TODO: make this class package-protected, and shift all callers to use IDevice

Fields Summary
static final String
RE_EMULATOR_SN
Emulator Serial Number regexp.
String
serialNumber
Serial number of the device
String
mAvdName
Name of the AVD
DeviceState
state
State of the device.
private final Map
mProperties
Device properties.
private final ArrayList
mClients
private DeviceMonitor
mMonitor
private SocketChannel
mSocketChannel
Socket for the connection monitoring client connection/disconnection.
Constructors Summary
Device(DeviceMonitor monitor)

        mMonitor = monitor;
    
Methods Summary
voidaddClient(com.android.ddmlib.Client client)

        synchronized (mClients) {
            mClients.add(client);
        }
    
voidaddProperty(java.lang.String label, java.lang.String value)

        mProperties.put(label, value);
    
voidclearClientList()

        synchronized (mClients) {
            mClients.clear();
        }
    
public booleancreateForward(int localPort, int remotePort)

        try {
            return AdbHelper.createForward(AndroidDebugBridge.sSocketAddr, this,
                    localPort, remotePort);
        } catch (IOException e) {
            Log.e("adb-forward", e); //$NON-NLS-1$
            return false;
        }
    
public voidexecuteShellCommand(java.lang.String command, IShellOutputReceiver receiver)

        AdbHelper.executeRemoteCommand(AndroidDebugBridge.sSocketAddr, command, this,
                receiver);
    
public java.lang.StringgetAvdName()

        return mAvdName;
    
public com.android.ddmlib.ClientgetClient(java.lang.String applicationName)

        synchronized (mClients) {
            for (Client c : mClients) {
                if (applicationName.equals(c.getClientData().getClientDescription())) {
                    return c;
                }
            }

        }

        return null;
    
java.util.ListgetClientList()

        return mClients;
    
java.nio.channels.SocketChannelgetClientMonitoringSocket()
Returns the client monitoring socket.

        return mSocketChannel;
    
public java.lang.StringgetClientName(int pid)

        synchronized (mClients) {
            for (Client c : mClients) {
                if (c.getClientData().getPid() == pid) {
                    return c.getClientData().getClientDescription();
                }
            }
        }

        return null;
    
public com.android.ddmlib.Client[]getClients()

        synchronized (mClients) {
            return mClients.toArray(new Client[mClients.size()]);
        }
    
public FileListingServicegetFileListingService()

        return new FileListingService(this);
    
DeviceMonitorgetMonitor()

        return mMonitor;
    
public java.util.MapgetProperties()

        return Collections.unmodifiableMap(mProperties);
    
public java.lang.StringgetProperty(java.lang.String name)

        return mProperties.get(name);
    
public intgetPropertyCount()

        return mProperties.size();
    
public RawImagegetScreenshot()

        return AdbHelper.getFrameBuffer(AndroidDebugBridge.sSocketAddr, this);
    
public java.lang.StringgetSerialNumber()


    /*
     * (non-Javadoc)
     * @see com.android.ddmlib.IDevice#getSerialNumber()
     */
       
        return serialNumber;
    
public com.android.ddmlib.Device$DeviceStategetState()

        return state;
    
public SyncServicegetSyncService()

        SyncService syncService = new SyncService(AndroidDebugBridge.sSocketAddr, this);
        if (syncService.openSync()) {
            return syncService;
         }

        return null;
    
booleanhasClient(int pid)

        synchronized (mClients) {
            for (Client client : mClients) {
                if (client.getClientData().getPid() == pid) {
                    return true;
                }
            }
        }

        return false;
    
public booleanhasClients()

        return mClients.size() > 0;
    
public booleanisBootLoader()

        return state == DeviceState.BOOTLOADER;
    
public booleanisEmulator()

        return serialNumber.matches(RE_EMULATOR_SN);
    
public booleanisOffline()

        return state == DeviceState.OFFLINE;
    
public booleanisOnline()

        return state == DeviceState.ONLINE;
    
voidremoveClient(com.android.ddmlib.Client client, boolean notify)
Removes a {@link Client} from the list.

param
client the client to remove.
param
notify Whether or not to notify the listeners of a change.

        mMonitor.addPortToAvailableList(client.getDebuggerListenPort());
        synchronized (mClients) {
            mClients.remove(client);
        }
        if (notify) {
            mMonitor.getServer().deviceChanged(this, CHANGE_CLIENT_LIST);
        }
    
public booleanremoveForward(int localPort, int remotePort)

        try {
            return AdbHelper.removeForward(AndroidDebugBridge.sSocketAddr, this,
                    localPort, remotePort);
        } catch (IOException e) {
            Log.e("adb-remove-forward", e); //$NON-NLS-1$
            return false;
        }
    
public voidrunEventLogService(com.android.ddmlib.log.LogReceiver receiver)

        AdbHelper.runEventLogService(AndroidDebugBridge.sSocketAddr, this, receiver);
    
public voidrunLogService(java.lang.String logname, com.android.ddmlib.log.LogReceiver receiver)

        AdbHelper.runLogService(AndroidDebugBridge.sSocketAddr, this, logname, receiver);
    
voidsetClientMonitoringSocket(java.nio.channels.SocketChannel socketChannel)
Sets the client monitoring socket.

param
socketChannel the sockets

        mSocketChannel = socketChannel;
    
public java.lang.StringtoString()

        return serialNumber;
    
voidupdate(int changeMask)

        mMonitor.getServer().deviceChanged(this, changeMask);
    
voidupdate(com.android.ddmlib.Client client, int changeMask)

        mMonitor.getServer().clientChanged(client, changeMask);