Implements toString in NanoAppMessage/ContextHubMessage

Bug: 31069172
Test: Compile only
Change-Id: I1b59bcd0ff75d3824a136b903e5db0c15b55ccf5
diff --git a/core/java/android/hardware/location/NanoAppMessage.java b/core/java/android/hardware/location/NanoAppMessage.java
index 716a194..6635258 100644
--- a/core/java/android/hardware/location/NanoAppMessage.java
+++ b/core/java/android/hardware/location/NanoAppMessage.java
@@ -28,6 +28,7 @@
  */
 @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 @@
                     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;
+    }
 }