Bug 1452200 - 3. Don't limit AndroidLog tag length; r=jchen
authorJim Chen <nchen@mozilla.com>
Sun, 15 Apr 2018 14:53:29 -0400
changeset 782432 7ff499dfcd51cf4a95ebf0db506b415bf7bb27c3
parent 782431 2627c8b0416336f330d6ac1f35f7973e0f4f57aa
child 782433 b5b17f347e0f98579c39f16c9a97ffb7ad7e9696
child 782435 add7d12e8400e969d3bf41a5549f9da9b69ce1a7
child 782449 1f3ea360b799ca178f1dbe35a699084d8fd10456
child 782451 12c38e71e02ee34c6fc3946e286932cea4b6b3c1
child 782461 0428c0ce5345c711540e6b332562106167afdbcc
child 782463 f17690fb1ff439a75bec362d77b1e2e55d5567a6
child 782467 9e501f87af345a9f9cd340fe858add1867aaaa74
child 782471 5542f08106c5f307243b6d20d382a9d939dd271b
child 782473 99e2dd379bde121960dffc2c65cb0e47b7045a5d
child 782477 f928975fae61642f0a8ca0794c6040e88edc2f1a
child 782481 47b3c832cbadde8968527f17aa477148f3fa451a
child 782856 2ad99f4d46d6c9ae17ee09ebc682fa8a045ad973
child 782866 1d1668f523d1892096fac42fc0f2c1c4905b2bc9
child 782890 04ae3ba01f9d12025f68dea5f6316f76f4c7a28f
child 782891 4a34418e88ddda39ec7dfb0bc32e81ae46c852ee
child 783089 d6ee83badbc458ce5468d4c6790f7e84c66272e9
child 783119 eede18ce54f4e80af16682f4e85015d38c70011b
child 783133 64f159d526d588fa7cbb1e6a9db60cf7285cab9f
child 783138 3572a8592f2d77f27d9f54a6365041cb0565ff36
child 783139 035730c33f8c2714b6dc1d66930bbac3cc7c2da2
child 783143 1fdbe2fd9a28fdcd3ca1c1c5645f09b7adc13e9f
child 783180 244294e7aae5b3022eabda9bee76380cfac34769
child 783356 b42b9ed89b00ef9aff0b557ab0fb6e54c5465cde
child 783368 7fa1f5577436112573deb1f6e9c759fd70f4bcc1
child 783412 c02d62a80cdbca2d38cf9495f9d335e395589cb3
child 783415 bff5716eb8931ae199d4f75e0c08a8cc7804cf69
child 783424 4646e4eda37c07dc29c7cec038cfde434f9c5cfb
child 783620 831989c17ad1041af3e1f9be0b7b10a0805a31cc
child 783626 e824fb6f49438892da2d833cb3b50e22462a4b13
child 783798 ead68897d5e4b0b36d4199c991ce6580be9ec726
child 783799 dee4092ff6847db5f0cc9551a99fcdc39ed09610
child 784015 48664fb60ed85499baecd91c2e5b29b6704a8929
child 784016 f88744e5edcf191e50d98ba3ba4f2a4e84bcab61
child 785816 13b5e760551db13e24be127a12137689355bfe9b
push id106534
push userbmo:mantaroh@gmail.com
push dateMon, 16 Apr 2018 00:49:06 +0000
reviewersjchen
bugs1452200
milestone61.0a1
Bug 1452200 - 3. Don't limit AndroidLog tag length; r=jchen In practice, Android never enforced restrictions on the tag length, and in newer versions, the restriction is removed, so we shouldn't limit the tag length at all. MozReview-Commit-ID: JQF9FBdB5Fj
mobile/android/modules/geckoview/AndroidLog.jsm
mobile/android/tests/browser/chrome/test_android_log.html
--- a/mobile/android/modules/geckoview/AndroidLog.jsm
+++ b/mobile/android/modules/geckoview/AndroidLog.jsm
@@ -48,36 +48,36 @@ if (typeof Components != "undefined") {
 // From <https://android.googlesource.com/platform/system/core/+/master/include/android/log.h>.
 const ANDROID_LOG_VERBOSE = 2;
 const ANDROID_LOG_DEBUG = 3;
 const ANDROID_LOG_INFO = 4;
 const ANDROID_LOG_WARN = 5;
 const ANDROID_LOG_ERROR = 6;
 
 // android.util.Log.isLoggable throws IllegalArgumentException if a tag length
-// exceeds 23 characters, and we prepend five characters ("Gecko") to every tag,
-// so we truncate tags exceeding 18 characters (although __android_log_write
-// itself and other android.util.Log methods don't seem to mind longer tags).
+// exceeds 23 characters, and we prepend five characters ("Gecko") to every tag.
+// However, __android_log_write itself and other android.util.Log methods don't
+// seem to mind longer tags.
 const MAX_TAG_LENGTH = 18;
 
 var liblog = ctypes.open("liblog.so"); // /system/lib/liblog.so
 var __android_log_write = liblog.declare("__android_log_write",
                                          ctypes.default_abi,
                                          ctypes.int, // return value: num bytes logged
                                          ctypes.int, // priority (ANDROID_LOG_* constant)
                                          ctypes.char.ptr, // tag
                                          ctypes.char.ptr); // message
 
 var AndroidLog = {
   MAX_TAG_LENGTH: MAX_TAG_LENGTH,
-  v: (tag, msg) => __android_log_write(ANDROID_LOG_VERBOSE, "Gecko" + tag.substring(0, MAX_TAG_LENGTH), msg),
-  d: (tag, msg) => __android_log_write(ANDROID_LOG_DEBUG, "Gecko" + tag.substring(0, MAX_TAG_LENGTH), msg),
-  i: (tag, msg) => __android_log_write(ANDROID_LOG_INFO, "Gecko" + tag.substring(0, MAX_TAG_LENGTH), msg),
-  w: (tag, msg) => __android_log_write(ANDROID_LOG_WARN, "Gecko" + tag.substring(0, MAX_TAG_LENGTH), msg),
-  e: (tag, msg) => __android_log_write(ANDROID_LOG_ERROR, "Gecko" + tag.substring(0, MAX_TAG_LENGTH), msg),
+  v: (tag, msg) => __android_log_write(ANDROID_LOG_VERBOSE, "Gecko" + tag, msg),
+  d: (tag, msg) => __android_log_write(ANDROID_LOG_DEBUG, "Gecko" + tag, msg),
+  i: (tag, msg) => __android_log_write(ANDROID_LOG_INFO, "Gecko" + tag, msg),
+  w: (tag, msg) => __android_log_write(ANDROID_LOG_WARN, "Gecko" + tag, msg),
+  e: (tag, msg) => __android_log_write(ANDROID_LOG_ERROR, "Gecko" + tag, msg),
 
   bind: function(tag) {
     return {
       MAX_TAG_LENGTH: MAX_TAG_LENGTH,
       v: AndroidLog.v.bind(null, tag),
       d: AndroidLog.d.bind(null, tag),
       i: AndroidLog.i.bind(null, tag),
       w: AndroidLog.w.bind(null, tag),
--- a/mobile/android/tests/browser/chrome/test_android_log.html
+++ b/mobile/android/tests/browser/chrome/test_android_log.html
@@ -65,21 +65,21 @@ Migrated from Robocop: https://bugzilla.
   is(DEBUG_BYTES, Log.d(DEBUG_MESSAGE), "debug bytes correct after bind");
   is(INFO_BYTES, Log.i(INFO_MESSAGE), "info bytes correct after bind");
   is(WARNING_BYTES, Log.w(WARNING_MESSAGE), "warning bytes correct after bind");
   is(ERROR_BYTES, Log.e(ERROR_MESSAGE), "error bytes correct after bind");
 
   // Ensure the functions work when the tag length is greater than the maximum
   // tag length.
   let tag = "X".repeat(AndroidLog.MAX_TAG_LENGTH + 1);
-  is(AndroidLog.MAX_TAG_LENGTH + 54, AndroidLog.v(tag, "This is a verbose message with a too-long tag."), "verbose message with too-long tag");
-  is(AndroidLog.MAX_TAG_LENGTH + 52, AndroidLog.d(tag, "This is a debug message with a too-long tag."), "debug message with too-long tag");
-  is(AndroidLog.MAX_TAG_LENGTH + 52, AndroidLog.i(tag, "This is an info message with a too-long tag."), "info message with too-long tag");
-  is(AndroidLog.MAX_TAG_LENGTH + 54, AndroidLog.w(tag, "This is a warning message with a too-long tag."), "warning message with too-long tag");
-  is(AndroidLog.MAX_TAG_LENGTH + 53, AndroidLog.e(tag, "This is an error message with a too-long tag."), "error message with too-long tag");
+  is(AndroidLog.MAX_TAG_LENGTH + 55, AndroidLog.v(tag, "This is a verbose message with a too-long tag."), "verbose message with too-long tag");
+  is(AndroidLog.MAX_TAG_LENGTH + 53, AndroidLog.d(tag, "This is a debug message with a too-long tag."), "debug message with too-long tag");
+  is(AndroidLog.MAX_TAG_LENGTH + 53, AndroidLog.i(tag, "This is an info message with a too-long tag."), "info message with too-long tag");
+  is(AndroidLog.MAX_TAG_LENGTH + 55, AndroidLog.w(tag, "This is a warning message with a too-long tag."), "warning message with too-long tag");
+  is(AndroidLog.MAX_TAG_LENGTH + 54, AndroidLog.e(tag, "This is an error message with a too-long tag."), "error message with too-long tag");
 
   // We should also ensure that the module is accessible from a ChromeWorker,
   // but there doesn't seem to be a way to load a ChromeWorker from this test.
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1004825">Mozilla Bug 1004825</a>