FileDocCategorySizeDatePackage
DdmHandleThread.javaAPI DocAndroid 5.1 API6065Thu Mar 12 22:22:10 GMT 2015android.ddm

DdmHandleThread

public class DdmHandleThread extends org.apache.harmony.dalvik.ddmc.ChunkHandler
Handle thread-related traffic.

Fields Summary
public static final int
CHUNK_THEN
public static final int
CHUNK_THCR
public static final int
CHUNK_THDE
public static final int
CHUNK_THST
public static final int
CHUNK_STKL
private static DdmHandleThread
mInstance
Constructors Summary
private DdmHandleThread()



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

private org.apache.harmony.dalvik.ddmc.ChunkcreateStackChunk(java.lang.StackTraceElement[] trace, int threadId)

        int bufferSize = 0;

        bufferSize += 4;            // version, flags, whatever
        bufferSize += 4;            // thread ID
        bufferSize += 4;            // frame count
        for (StackTraceElement elem : trace) {
            bufferSize += 4 + elem.getClassName().length() * 2;
            bufferSize += 4 + elem.getMethodName().length() * 2;
            bufferSize += 4;
            if (elem.getFileName() != null)
                bufferSize += elem.getFileName().length() * 2;
            bufferSize += 4;        // line number
        }

        ByteBuffer out = ByteBuffer.allocate(bufferSize);
        out.putInt(0);
        out.putInt(threadId);
        out.putInt(trace.length);
        for (StackTraceElement elem : trace) {
            out.putInt(elem.getClassName().length());
            putString(out, elem.getClassName());
            out.putInt(elem.getMethodName().length());
            putString(out, elem.getMethodName());
            if (elem.getFileName() != null) {
                out.putInt(elem.getFileName().length());
                putString(out, elem.getFileName());
            } else {
                out.putInt(0);
            }
            out.putInt(elem.getLineNumber());
        }

        return new Chunk(CHUNK_STKL, out);
    
public voiddisconnected()
Called when the DDM server disconnects. Can be used to disable periodic transmissions or clean up saved state.

public org.apache.harmony.dalvik.ddmc.ChunkhandleChunk(org.apache.harmony.dalvik.ddmc.Chunk request)
Handle a chunk of data.

        if (false)
            Log.v("ddm-thread", "Handling " + name(request.type) + " chunk");
        int type = request.type;

        if (type == CHUNK_THEN) {
            return handleTHEN(request);
        } else if (type == CHUNK_THST) {
            return handleTHST(request);
        } else if (type == CHUNK_STKL) {
            return handleSTKL(request);
        } else {
            throw new RuntimeException("Unknown packet "
                + ChunkHandler.name(type));
        }
    
private org.apache.harmony.dalvik.ddmc.ChunkhandleSTKL(org.apache.harmony.dalvik.ddmc.Chunk request)

        ByteBuffer in = wrapChunk(request);
        int threadId;

        threadId = in.getInt();

        //Log.d("ddm-thread", "Stack list request " + threadId);

        StackTraceElement[] trace = DdmVmInternal.getStackTraceById(threadId);
        if (trace == null) {
            return createFailChunk(1, "Stack trace unavailable");
        } else {
            return createStackChunk(trace, threadId);
        }
    
private org.apache.harmony.dalvik.ddmc.ChunkhandleTHEN(org.apache.harmony.dalvik.ddmc.Chunk request)

        ByteBuffer in = wrapChunk(request);

        boolean enable = (in.get() != 0);
        //Log.i("ddm-thread", "Thread notify enable: " + enable);

        DdmVmInternal.threadNotify(enable);
        return null;        // empty response
    
private org.apache.harmony.dalvik.ddmc.ChunkhandleTHST(org.apache.harmony.dalvik.ddmc.Chunk request)

        ByteBuffer in = wrapChunk(request);
        // currently nothing to read from "in"

        //Log.d("ddm-thread", "Thread status request");

        byte[] status = DdmVmInternal.getThreadStats();
        if (status != null)
            return new Chunk(CHUNK_THST, status, 0, status.length);
        else
            return createFailChunk(1, "Can't build THST chunk");
    
public static voidregister()
Register for the messages we're interested in.

        DdmServer.registerHandler(CHUNK_THEN, mInstance);
        DdmServer.registerHandler(CHUNK_THST, mInstance);
        DdmServer.registerHandler(CHUNK_STKL, mInstance);