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

Commit 1d3b23cb authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Implements toString in NanoAppMessage/ContextHubMessage

Bug: 31069172
Test: Compile only
Change-Id: I1b59bcd0ff75d3824a136b903e5db0c15b55ccf5
parent bd56951c
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -34,12 +34,11 @@ import java.util.Arrays;
@SystemApi
@Deprecated
public class ContextHubMessage {
    private static final int DEBUG_LOG_NUM_BYTES = 16;
    private int mType;
    private int mVersion;
    private byte[]mData;

    private static final String TAG = "ContextHubMessage";

    /**
     * Get the message type
     *
@@ -136,4 +135,28 @@ public class ContextHubMessage {
            return new ContextHubMessage[size];
        }
    };

    @Override
    public String toString() {
        int length = mData.length;

        String ret =
                "ContextHubMessage[type = " + mType + ", length = " + mData.length + " bytes](";
        if (length > 0) {
            ret += "data = 0x";
        }
        for (int i = 0; i < Math.min(length, DEBUG_LOG_NUM_BYTES); i++) {
            ret += Byte.toHexString(mData[i], true /* upperCase */);

            if ((i + 1) % 4 == 0) {
                ret += " ";
            }
        }
        if (length > DEBUG_LOG_NUM_BYTES) {
            ret += "...";
        }
        ret += ")";

        return ret;
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.Parcelable;
 */
@SystemApi
public final class NanoAppMessage implements Parcelable {
    private static final int DEBUG_LOG_NUM_BYTES = 16;
    private long mNanoAppId;
    private int mMessageType;
    private byte[] mMessageBody;
@@ -142,4 +143,29 @@ public final class NanoAppMessage implements Parcelable {
                    return new NanoAppMessage[size];
                }
            };

    @Override
    public String toString() {
        int length = mMessageBody.length;

        String ret = "NanoAppMessage[type = " + mMessageType + ", length = " + mMessageBody.length
                + " bytes, " + (mIsBroadcasted ? "broadcast" : "unicast") + ", nanoapp = 0x"
                + Long.toHexString(mNanoAppId) + "](";
        if (length > 0) {
            ret += "data = 0x";
        }
        for (int i = 0; i < Math.min(length, DEBUG_LOG_NUM_BYTES); i++) {
            ret += Byte.toHexString(mMessageBody[i], true /* upperCase */);

            if ((i + 1) % 4 == 0) {
                ret += " ";
            }
        }
        if (length > DEBUG_LOG_NUM_BYTES) {
            ret += "...";
        }
        ret += ")";

        return ret;
    }
}
+1 −3
Original line number Diff line number Diff line
@@ -113,9 +113,7 @@ import java.util.function.Consumer;
        NanoAppMessage clientMessage = ContextHubServiceUtil.createNanoAppMessage(message);

        if (DEBUG_LOG_ENABLED) {
            String targetAudience = clientMessage.isBroadcastMessage() ? "broadcast" : "unicast";
            Log.v(TAG, "Received a " + targetAudience + " message from nanoapp 0x"
                    + Long.toHexString(clientMessage.getNanoAppId()));
            Log.v(TAG, "Received " + clientMessage);
        }

        if (clientMessage.isBroadcastMessage()) {