Search in sources :

Example 1 with Chunk

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

the class DdmHandleHello method handleHELO.

/*
     * Handle introductory packet.
     */
private Chunk handleHELO(Chunk request) {
    if (false)
        return createFailChunk(123, "This is a test");
    /*
         * Process the request.
         */
    ByteBuffer in = wrapChunk(request);
    int serverProtoVers = in.getInt();
    if (false)
        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(20 + 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);
    out.putInt(UserHandle.myUserId());
    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;
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Chunk

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

the class DdmHandleThread method handleTHST.

/*
     * Handle a "THread STatus" request.  This is constructed by the VM.
     */
private Chunk handleTHST(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");
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Chunk

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

the class DdmHandleViewDebug method captureLayers.

/** Returns a buffer with region details & bitmap of every single view. */
private Chunk captureLayers(View rootView) {
    ByteArrayOutputStream b = new ByteArrayOutputStream(1024);
    DataOutputStream dos = new DataOutputStream(b);
    try {
        ViewDebug.captureLayers(rootView, dos);
    } catch (IOException e) {
        return createFailChunk(1, "Unexpected error while obtaining view hierarchy: " + e.getMessage());
    } finally {
        try {
            dos.close();
        } catch (IOException e) {
        // ignore
        }
    }
    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VURT, data, 0, data.length);
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk)

Example 4 with Chunk

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

the class DdmHandleViewDebug method profileView.

/** Profiles provided view. */
private Chunk profileView(View rootView, final View targetView) {
    ByteArrayOutputStream b = new ByteArrayOutputStream(32 * 1024);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(b), 32 * 1024);
    try {
        ViewDebug.profileViewAndChildren(targetView, bw);
    } catch (IOException e) {
        return createFailChunk(1, "Unexpected error while profiling view: " + e.getMessage());
    } finally {
        try {
            bw.close();
        } catch (IOException e) {
        // ignore
        }
    }
    byte[] data = b.toByteArray();
    return new Chunk(CHUNK_VUOP, data, 0, data.length);
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Chunk(org.apache.harmony.dalvik.ddmc.Chunk) BufferedWriter(java.io.BufferedWriter)

Example 5 with Chunk

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

the class DdmHandleHeap method handleHPDU.

/*
     * Handle a "HeaP DUmp" request.
     *
     * This currently just returns a result code.  We could pull up
     * the entire contents of the file and return them, but hprof dump
     * files can be a few megabytes.
     */
private Chunk handleHPDU(Chunk request) {
    ByteBuffer in = wrapChunk(request);
    byte result;
    /* get the filename for the output file */
    int len = in.getInt();
    String fileName = getString(in, len);
    if (false)
        Log.d("ddm-heap", "Heap dump: file='" + fileName + "'");
    try {
        Debug.dumpHprofData(fileName);
        result = 0;
    } catch (UnsupportedOperationException uoe) {
        Log.w("ddm-heap", "hprof dumps not supported in this VM");
        result = -1;
    } catch (IOException ioe) {
        result = -1;
    } catch (RuntimeException re) {
        result = -1;
    }
    /* create a non-empty reply so the handler fires on completion */
    byte[] reply = { result };
    return new Chunk(CHUNK_HPDU, reply, 0, reply.length);
}
Also used : IOException(java.io.IOException) 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