Search in sources :

Example 46 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by crdroidandroid.

the class DdmHandleHello method sendWAIT.

/**
     * Send up a WAIT chunk.  The only currently defined value for "reason"
     * is zero, which means "waiting for a debugger".
     */
public static void sendWAIT(int reason) {
    byte[] data = new byte[] { (byte) reason };
    Chunk waitChunk = new Chunk(CHUNK_WAIT, data, 0, 1);
    DdmServer.sendChunk(waitChunk);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 47 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by crdroidandroid.

the class DdmHandleViewDebug method dumpHierarchy.

/**
     * Returns the view hierarchy and/or view properties starting at the provided view.
     * Based on the input options, the return data may include:
     *  - just the view hierarchy
     *  - view hierarchy & the properties for each of the views
     *  - just the view properties for a specific view.
     *  TODO: Currently this only returns views starting at the root, need to fix so that
     *  it can return properties of any view.
     */
private Chunk dumpHierarchy(View rootView, ByteBuffer in) {
    boolean skipChildren = in.getInt() > 0;
    boolean includeProperties = in.getInt() > 0;
    boolean v2 = in.hasRemaining() && in.getInt() > 0;
    long start = System.currentTimeMillis();
    ByteArrayOutputStream b = new ByteArrayOutputStream(2 * 1024 * 1024);
    try {
        if (v2) {
            ViewDebug.dumpv2(rootView, b);
        } else {
            ViewDebug.dump(rootView, skipChildren, includeProperties, b);
        }
    } catch (IOException | InterruptedException e) {
        return createFailChunk(1, "Unexpected error while obtaining view hierarchy: " + e.getMessage());
    }
    long end = System.currentTimeMillis();
    Log.d(TAG, "Time to obtain view hierarchy (ms): " + (end - start));
    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VURT, data, 0, data.length);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 48 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by crdroidandroid.

the class DdmHandleViewDebug method captureView.

private Chunk captureView(View rootView, View targetView) {
    ByteArrayOutputStream b = new ByteArrayOutputStream(1024);
    try {
        ViewDebug.capture(rootView, b, targetView);
    } catch (IOException e) {
        return createFailChunk(1, "Unexpected error while capturing view: " + e.getMessage());
    }
    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VUOP, data, 0, data.length);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 49 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by crdroidandroid.

the class DdmHandleHello method handleFEAT.

/*
     * Handle request for list of supported features.
     */
private Chunk handleFEAT(Chunk request) {
    // TODO: query the VM to ensure that support for these features
    // is actually compiled in
    final String[] vmFeatures = Debug.getVmFeatureList();
    if (false)
        Log.v("ddm-heap", "Got feature list request");
    int size = 4 + 4 * (vmFeatures.length + FRAMEWORK_FEATURES.length);
    for (int i = vmFeatures.length - 1; i >= 0; i--) size += vmFeatures[i].length() * 2;
    for (int i = FRAMEWORK_FEATURES.length - 1; i >= 0; i--) size += FRAMEWORK_FEATURES[i].length() * 2;
    ByteBuffer out = ByteBuffer.allocate(size);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(vmFeatures.length + FRAMEWORK_FEATURES.length);
    for (int i = vmFeatures.length - 1; i >= 0; i--) {
        out.putInt(vmFeatures[i].length());
        putString(out, vmFeatures[i]);
    }
    for (int i = FRAMEWORK_FEATURES.length - 1; i >= 0; i--) {
        out.putInt(FRAMEWORK_FEATURES[i].length());
        putString(out, FRAMEWORK_FEATURES[i]);
    }
    return new Chunk(CHUNK_FEAT, out);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 50 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project android_frameworks_base by crdroidandroid.

the class DdmHandleThread method createStackChunk.

/*
     * Serialize a StackTraceElement[] into an STKL chunk.
     *
     * We include the threadId in the response so the other side doesn't have
     * to match up requests and responses as carefully.
     */
private Chunk createStackChunk(StackTraceElement[] trace, int threadId) {
    int bufferSize = 0;
    // version, flags, whatever
    bufferSize += 4;
    // thread ID
    bufferSize += 4;
    // frame count
    bufferSize += 4;
    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;
        // line number
        bufferSize += 4;
    }
    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);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Chunk (org.apache.harmony.dalvik.ddmc.Chunk)98 ByteBuffer (java.nio.ByteBuffer)48 IOException (java.io.IOException)36 ByteArrayOutputStream (java.io.ByteArrayOutputStream)29 BufferedWriter (java.io.BufferedWriter)6 DataOutputStream (java.io.DataOutputStream)6 OutputStreamWriter (java.io.OutputStreamWriter)6 VMRuntime (dalvik.system.VMRuntime)5