Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e3c0875 authored by vichang's avatar vichang Committed by Automerger Merge Worker
Browse files

Merge "Refactor ddm ChunkHandler utility methods from libcore to framework"...

Merge "Refactor ddm ChunkHandler utility methods from libcore to framework" am: efc3806b am: 2d170271 am: 7da86d8d

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1686655

Change-Id: Id8366338726907fd7a7ad1248f4482906ed235dc
parents 598fe132 7da86d8d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6413,7 +6413,7 @@ public final class ActivityThread extends ClientTransactionHandler
            VMDebug.setAllocTrackerStackDepth(Integer.parseInt(property));
        }
        if (data.trackAllocation) {
            DdmVmInternal.enableRecentAllocations(true);
            DdmVmInternal.setRecentAllocationsTrackingEnabled(true);
        }
        // Note when this process has started.
        Process.setStartTimes(SystemClock.elapsedRealtime(), SystemClock.uptimeMillis());
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.ddm;

import org.apache.harmony.dalvik.ddmc.ChunkHandler;

import java.nio.ByteBuffer;

/**
 * Contains utility methods for chunk serialization and deserialization.
 */
public abstract class DdmHandle extends ChunkHandler {

    /**
     * Utility function to copy a String out of a ByteBuffer.
     *
     * This is here because multiple chunk handlers can make use of it,
     * and there's nowhere better to put it.
     */
    public static String getString(ByteBuffer buf, int len) {
        char[] data = new char[len];
        for (int i = 0; i < len; i++) {
            data[i] = buf.getChar();
        }
        return new String(data);
    }

    /**
     * Utility function to copy a String into a ByteBuffer.
     */
    public static void putString(ByteBuffer buf, String str) {
        int len = str.length();
        for (int i = 0; i < len; i++) {
            buf.putChar(str.charAt(i));
        }
    }

}
+4 −4
Original line number Diff line number Diff line
@@ -30,9 +30,9 @@ import java.nio.ByteBuffer;
/**
 * Track our app name.  We don't (currently) handle any inbound packets.
 */
public class DdmHandleAppName extends ChunkHandler {
public class DdmHandleAppName extends DdmHandle {

    public static final int CHUNK_APNM = type("APNM");
    public static final int CHUNK_APNM = ChunkHandler.type("APNM");

    private static volatile Names sNames = new Names("", "");

@@ -51,13 +51,13 @@ public class DdmHandleAppName extends ChunkHandler {
     * Called when the DDM server connects.  The handler is allowed to
     * send messages to the server.
     */
    public void connected() {}
    public void onConnected() {}

    /**
     * Called when the DDM server disconnects.  Can be used to disable
     * periodic transmissions or clean up saved state.
     */
    public void disconnected() {}
    public void onDisconnected() {}

    /**
     * Handle a chunk of data.
+7 −5
Original line number Diff line number Diff line
@@ -16,18 +16,20 @@

package android.ddm;

import android.util.Log;

import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import android.util.Log;

import java.nio.ByteBuffer;

/**
 * Handle an EXIT chunk.
 */
public class DdmHandleExit extends ChunkHandler {
public class DdmHandleExit extends DdmHandle {

    public static final int CHUNK_EXIT = type("EXIT");
    public static final int CHUNK_EXIT = ChunkHandler.type("EXIT");

    private static DdmHandleExit mInstance = new DdmHandleExit();

@@ -46,13 +48,13 @@ public class DdmHandleExit extends ChunkHandler {
     * Called when the DDM server connects.  The handler is allowed to
     * send messages to the server.
     */
    public void connected() {}
    public void onConnected() {}

    /**
     * Called when the DDM server disconnects.  Can be used to disable
     * periodic transmissions or clean up saved state.
     */
    public void disconnected() {}
    public void onDisconnected() {}

    /**
     * Handle a chunk of data.  We're only registered for "EXIT".
+7 −11
Original line number Diff line number Diff line
@@ -16,21 +16,18 @@

package android.ddm;

import android.util.Log;

import org.apache.harmony.dalvik.ddmc.Chunk;
import org.apache.harmony.dalvik.ddmc.ChunkHandler;
import org.apache.harmony.dalvik.ddmc.DdmServer;
import org.apache.harmony.dalvik.ddmc.DdmVmInternal;
import android.os.Debug;
import android.util.Log;
import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * Handle native and virtual heap requests.
 */
public class DdmHandleHeap extends ChunkHandler {
public class DdmHandleHeap extends DdmHandle {

    public static final int CHUNK_HPGC = type("HPGC");
    public static final int CHUNK_HPGC = ChunkHandler.type("HPGC");

    private static DdmHandleHeap mInstance = new DdmHandleHeap();

@@ -49,13 +46,13 @@ public class DdmHandleHeap extends ChunkHandler {
     * Called when the DDM server connects.  The handler is allowed to
     * send messages to the server.
     */
    public void connected() {}
    public void onConnected() {}

    /**
     * Called when the DDM server disconnects.  Can be used to disable
     * periodic transmissions or clean up saved state.
     */
    public void disconnected() {}
    public void onDisconnected() {}

    /**
     * Handle a chunk of data.
@@ -68,8 +65,7 @@ public class DdmHandleHeap extends ChunkHandler {
        if (type == CHUNK_HPGC) {
            return handleHPGC(request);
        } else {
            throw new RuntimeException("Unknown packet "
                + ChunkHandler.name(type));
            throw new RuntimeException("Unknown packet " + name(type));
        }
    }

Loading