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
--- 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>