Skip to content

Commit

Permalink
[andr] Avoid noisy replay logs (#189)
Browse files Browse the repository at this point in the history
* Avoid calling getResourceEntryName() when we know it's an invalid id

* format

* ignore MaxLineLength rule for long comments
  • Loading branch information
murki authored Jan 21, 2025
1 parent 5104601 commit dd26286
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal class ViewMapper(
private fun View.viewToReplayRect(): List<ReplayRect> {
val list = mutableListOf<ReplayRect>()
val resourceName =
if (id != View.NO_ID && id != ResourcesCompat.ID_NULL) {
if (isValidResId(this.id)) {
try {
resources.getResourceEntryName(this.id)
} catch (ignore: Resources.NotFoundException) {
Expand All @@ -72,7 +72,7 @@ internal class ViewMapper(
"Failed to retrieve ID"
}
} else {
"no_resource_id"
"invalid_resource_id"
}

val type = viewMapperConfiguration.mapper[this.javaClass.simpleName]
Expand Down Expand Up @@ -100,4 +100,15 @@ internal class ViewMapper(
}
return list
}

private fun isValidResId(resId: Int): Boolean {
@Suppress("MaxLineLength")
// the checks below are to avoid spamming logcat with errors emitted by the Android sub-system when calling resources.getResourceEntryName(invalidResourceId)
// see: https://cs.android.com/android/platform/superproject/main/+/6adcde7195b0c9efd344a2bec2412909ab66d047:frameworks/base/libs/androidfw/AssetManager2.cpp;l=657
// lifted from: https://cs.android.com/android/platform/superproject/main/+/a2a9539615425091c7413249e5dc063009cf222b:frameworks/base/libs/androidfw/include/androidfw/ResourceUtils.h;l=62
return resId != View.NO_ID &&
resId != ResourcesCompat.ID_NULL &&
(resId.toUInt() and 0x00ff0000u) != 0u &&
(resId.toUInt() and 0xff000000u) != 0u
}
}

0 comments on commit dd26286

Please sign in to comment.