FileDocCategorySizeDatePackage
DdmHandleHello.javaAPI DocAndroid 1.5 API4229Wed May 06 22:41:54 BST 2009android.ddm

DdmHandleHello

public class DdmHandleHello extends org.apache.harmony.dalvik.ddmc.ChunkHandler
Handle a HELO chunk.

Fields Summary
public static final int
CHUNK_HELO
public static final int
CHUNK_WAIT
private static DdmHandleHello
mInstance
Constructors Summary
private DdmHandleHello()



    /* singleton, do not instantiate */
      
Methods Summary
public voidconnected()
Called when the DDM server connects. The handler is allowed to send messages to the server.

        if (Config.LOGV)
            Log.v("ddm-hello", "Connected!");

        if (true) {
            /* test spontaneous transmission */
            byte[] data = new byte[] { 0, 1, 2, 3, 4, -4, -3, -2, -1, 127 };
            Chunk testChunk =
                new Chunk(ChunkHandler.type("TEST"), data, 1, data.length-2);
            DdmServer.sendChunk(testChunk);
        }
    
public voiddisconnected()
Called when the DDM server disconnects. Can be used to disable periodic transmissions or clean up saved state.

        if (Config.LOGV)
            Log.v("ddm-hello", "Disconnected!");
    
public org.apache.harmony.dalvik.ddmc.ChunkhandleChunk(org.apache.harmony.dalvik.ddmc.Chunk request)
Handle a chunk of data. We're only registered for "HELO".

        if (Config.LOGV)
            Log.v("ddm-hello", "Handling " + name(request.type) + " chunk");

        if (false)
            return createFailChunk(123, "This is a test");

        /*
         * Process the request.
         */
        ByteBuffer in = wrapChunk(request);

        int serverProtoVers = in.getInt();
        if (Config.LOGV)
            Log.v("ddm-hello", "Server version is " + serverProtoVers);

        /*
         * Create a response.
         */
        String vmName = System.getProperty("java.vm.name", "?");
        String vmVersion = System.getProperty("java.vm.version", "?");
        String vmIdent = vmName + " v" + vmVersion;

        //String appName = android.app.ActivityThread.currentPackageName();
        //if (appName == null)
        //    appName = "unknown";
        String appName = DdmHandleAppName.getAppName();

        ByteBuffer out = ByteBuffer.allocate(16
                            + vmIdent.length()*2 + appName.length()*2);
        out.order(ChunkHandler.CHUNK_ORDER);
        out.putInt(DdmServer.CLIENT_PROTOCOL_VERSION);
        out.putInt(android.os.Process.myPid());
        out.putInt(vmIdent.length());
        out.putInt(appName.length());
        putString(out, vmIdent);
        putString(out, appName);

        Chunk reply = new Chunk(CHUNK_HELO, out);

        /*
         * Take the opportunity to inform DDMS if we are waiting for a
         * debugger to attach.
         */
        if (Debug.waitingForDebugger())
            sendWAIT(0);

        return reply;
    
public static voidregister()
Register for the messages we're interested in.

        DdmServer.registerHandler(CHUNK_HELO, mInstance);
    
public static voidsendWAIT(int reason)
Send up a WAIT chunk. The only currently defined value for "reason" is zero, which means "waiting for a debugger".

        byte[] data = new byte[] { (byte) reason };
        Chunk waitChunk = new Chunk(CHUNK_WAIT, data, 0, 1);
        DdmServer.sendChunk(waitChunk);