Search in sources :

Example 6 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.

the class DdmHandleAppName method sendAPNM.

/*
     * Send an APNM (APplication NaMe) chunk.
     */
private static void sendAPNM(String appName, int userId) {
    if (false)
        Log.v("ddm", "Sending app name");
    ByteBuffer out = ByteBuffer.allocate(4 + /* appName's length */
    appName.length() * 2 + /* appName */
    4);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(appName.length());
    putString(out, appName);
    out.putInt(userId);
    Chunk chunk = new Chunk(CHUNK_APNM, out);
    DdmServer.sendChunk(chunk);
}
Also used : Chunk(org.apache.harmony.dalvik.ddmc.Chunk) ByteBuffer(java.nio.ByteBuffer)

Example 7 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.

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)

Example 8 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.

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 9 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.

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 10 with Chunk

use of org.apache.harmony.dalvik.ddmc.Chunk in project platform_frameworks_base by android.

the class DdmHandleHello method handleHELO.

/*
     * Handle introductory packet. This is called during JNI_CreateJavaVM
     * before frameworks native methods are registered, so be careful not
     * to call any APIs that depend on frameworks native code.
     */
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();
    VMRuntime vmRuntime = VMRuntime.getRuntime();
    String instructionSetDescription = vmRuntime.is64Bit() ? "64-bit" : "32-bit";
    String vmInstructionSet = vmRuntime.vmInstructionSet();
    if (vmInstructionSet != null && vmInstructionSet.length() > 0) {
        instructionSetDescription += " (" + vmInstructionSet + ")";
    }
    String vmFlags = "CheckJNI=" + (vmRuntime.isCheckJniEnabled() ? "true" : "false");
    boolean isNativeDebuggable = vmRuntime.isNativeDebuggable();
    ByteBuffer out = ByteBuffer.allocate(28 + vmIdent.length() * 2 + appName.length() * 2 + instructionSetDescription.length() * 2 + vmFlags.length() * 2 + 1);
    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());
    out.putInt(instructionSetDescription.length());
    putString(out, instructionSetDescription);
    out.putInt(vmFlags.length());
    putString(out, vmFlags);
    out.put((byte) (isNativeDebuggable ? 1 : 0));
    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 : VMRuntime(dalvik.system.VMRuntime) 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