From 50d05a6495492943862562cb93688b17a6a46f65 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Ricau Date: Wed, 28 Jun 2023 15:40:19 -0700 Subject: [PATCH] Bring in latest batch of known leaks --- shark-android/api/shark-android.api | 8 ++ .../java/shark/AndroidObjectInspectors.kt | 8 ++ .../java/shark/AndroidReferenceMatchers.kt | 98 ++++++++++++++++--- 3 files changed, 101 insertions(+), 13 deletions(-) diff --git a/shark-android/api/shark-android.api b/shark-android/api/shark-android.api index 75a7a05193..ece1532593 100644 --- a/shark-android/api/shark-android.api +++ b/shark-android/api/shark-android.api @@ -22,6 +22,7 @@ public final class shark/AndroidMetadataExtractor : shark/MetadataExtractor { public abstract class shark/AndroidObjectInspectors : java/lang/Enum, shark/ObjectInspector { public static final field ACTIVITY Lshark/AndroidObjectInspectors; + public static final field ACTIVITY_THREAD Lshark/AndroidObjectInspectors; public static final field ANDROIDX_FRAGMENT Lshark/AndroidObjectInspectors; public static final field ANIMATOR Lshark/AndroidObjectInspectors; public static final field APPLICATION Lshark/AndroidObjectInspectors; @@ -78,6 +79,7 @@ public abstract class shark/AndroidReferenceMatchers : java/lang/Enum { public static final field ASSIST_STRUCTURE Lshark/AndroidReferenceMatchers; public static final field AUDIO_MANAGER Lshark/AndroidReferenceMatchers; public static final field AUDIO_MANAGER__MCONTEXT_STATIC Lshark/AndroidReferenceMatchers; + public static final field AW_CONTENTS__A0 Lshark/AndroidReferenceMatchers; public static final field AW_RESOURCE__SRESOURCES Lshark/AndroidReferenceMatchers; public static final field BACKDROP_FRAME_RENDERER__MDECORVIEW Lshark/AndroidReferenceMatchers; public static final field BIOMETRIC_PROMPT Lshark/AndroidReferenceMatchers; @@ -91,11 +93,14 @@ public abstract class shark/AndroidReferenceMatchers : java/lang/Enum { public static final field CONTROLLED_INPUT_CONNECTION_WRAPPER Lshark/AndroidReferenceMatchers; public static final field Companion Lshark/AndroidReferenceMatchers$Companion; public static final field DEVICE_POLICY_MANAGER__SETTINGS_OBSERVER Lshark/AndroidReferenceMatchers; + public static final field DREAM_SERVICE Lshark/AndroidReferenceMatchers; public static final field EDITTEXT_BLINK_MESSAGEQUEUE Lshark/AndroidReferenceMatchers; public static final field EVENT_RECEIVER__MMESSAGE_QUEUE Lshark/AndroidReferenceMatchers; public static final field EXTENDED_STATUS_BAR_MANAGER Lshark/AndroidReferenceMatchers; public static final field FINALIZER_WATCHDOG_DAEMON Lshark/AndroidReferenceMatchers; + public static final field FLIPPER__APPLICATION_DESCRIPTOR Lshark/AndroidReferenceMatchers; public static final field GESTURE_BOOST_MANAGER Lshark/AndroidReferenceMatchers; + public static final field HMD_GLOBAL Ljava/lang/String; public static final field HOST_ADPU_SERVICE_MSG_HANDLER Lshark/AndroidReferenceMatchers; public static final field HUAWEI Ljava/lang/String; public static final field IMM_CURRENT_INPUT_CONNECTION Lshark/AndroidReferenceMatchers; @@ -104,6 +109,7 @@ public abstract class shark/AndroidReferenceMatchers : java/lang/Enum { public static final field INPUT_METHOD_MANAGER_IS_TERRIBLE Lshark/AndroidReferenceMatchers; public static final field INSTRUMENTATION_RECOMMEND_ACTIVITY Lshark/AndroidReferenceMatchers; public static final field IREQUEST_FINISH_CALLBACK Lshark/AndroidReferenceMatchers; + public static final field JOB_SERVICE Lshark/AndroidReferenceMatchers; public static final field LAYOUT_TRANSITION Lshark/AndroidReferenceMatchers; public static final field LEAK_CANARY_HEAP_DUMPER Lshark/AndroidReferenceMatchers; public static final field LEAK_CANARY_INTERNAL Lshark/AndroidReferenceMatchers; @@ -156,6 +162,8 @@ public abstract class shark/AndroidReferenceMatchers : java/lang/Enum { public static final field VIEW_GROUP__M_PRE_SORTED_CHILDREN Lshark/AndroidReferenceMatchers; public static final field VIVO Ljava/lang/String; public static final field WINDOW_ON_BACK_INVOKED_DISPATCHER__STUB Lshark/AndroidReferenceMatchers; + public static final field XIAMI__RESOURCES_IMPL Lshark/AndroidReferenceMatchers; + public static final field XIAOMI Ljava/lang/String; public synthetic fun (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public static final fun buildKnownReferences (Ljava/util/Set;)Ljava/util/List; public static final fun getAppDefaults ()Ljava/util/List; diff --git a/shark-android/src/main/java/shark/AndroidObjectInspectors.kt b/shark-android/src/main/java/shark/AndroidObjectInspectors.kt index cda50362cb..a744c98e95 100644 --- a/shark-android/src/main/java/shark/AndroidObjectInspectors.kt +++ b/shark-android/src/main/java/shark/AndroidObjectInspectors.kt @@ -376,6 +376,14 @@ enum class AndroidObjectInspectors : ObjectInspector { } }, + ACTIVITY_THREAD { + override fun inspect(reporter: ObjectReporter) { + reporter.whenInstanceOf("android.app.ActivityThread") { + notLeakingReasons += "ActivityThread is a singleton" + } + } + }, + APPLICATION { override fun inspect( reporter: ObjectReporter diff --git a/shark-android/src/main/java/shark/AndroidReferenceMatchers.kt b/shark-android/src/main/java/shark/AndroidReferenceMatchers.kt index b2e1c8d57b..e47fbcda25 100644 --- a/shark-android/src/main/java/shark/AndroidReferenceMatchers.kt +++ b/shark-android/src/main/java/shark/AndroidReferenceMatchers.kt @@ -245,7 +245,7 @@ enum class AndroidReferenceMatchers { InputMethodManager.mImeInsetsConsumer isn't set to null when the activity is destroyed. """.trimIndent() ) { - sdkInt == 31 + sdkInt >= 31 } } }, @@ -541,7 +541,7 @@ enum class AndroidReferenceMatchers { " on the screen. TextView.ChangeWatcher and android.widget.Editor end up in spans and" + " typically hold on to the view hierarchy" ) { - sdkInt in 24..30 + sdkInt >= 24 } } }, @@ -814,15 +814,17 @@ enum class AndroidReferenceMatchers { override fun add( references: MutableList ) { - references += instanceFieldLeak( - "android.app.AppOpsManager\$3", "this\$0", + references += nativeGlobalVariableLeak( + "android.app.AppOpsManager\$3", description = """ - AppOpsManager\$3 implements IAppOpsActiveCallback.Stub and is held by a native ref and - holds on to am AppOpsManager which references an activity context. - Report: https://issuetracker.google.com/issues/210899127 + Fix: Update androidx.core:core to 1.10.0-alpha01 or greater as it includes an Android 12 + fix for this leak on Android 12, see https://github.com/androidx/androidx/pull/435 . + AppOpsManager\$3 implements IAppOpsActiveCallback.Stub and is held by a native ref long + until the calling side gets GCed, which can happen long after the stub is no longer of + use. """.trimIndent() ) { - sdkInt in 31..33 + sdkInt in 31..32 } } }, @@ -895,6 +897,60 @@ enum class AndroidReferenceMatchers { } }, + FLIPPER__APPLICATION_DESCRIPTOR { + override fun add( + references: MutableList + ) { + references += staticFieldLeak( + "com.facebook.flipper.plugins.inspector.descriptors.ApplicationDescriptor", "editedDelegates", + description = """ + Flipper's ApplicationDescriptor leaks root views after they've been detached. + https://github.com/facebook/flipper/issues/4270 + """.trimIndent() + ) + } + }, + + AW_CONTENTS__A0 { + override fun add(references: MutableList) { + staticFieldLeak( + "org.chromium.android_webview.AwContents", + "A0", + description = """ + WindowAndroidWrapper has a strong ref to the context key so this breaks the WeakHashMap + contracts and WeakHashMap is unable to perform its job of auto cleaning. + https://github.com/square/leakcanary/issues/2538 + """.trimIndent() + ) + } + }, + + JOB_SERVICE { + override fun add( + references: MutableList + ) { + AndroidReferenceMatchers.nativeGlobalVariableLeak( + className = "android.app.job.JobService\$1", + description = """ + JobService used to be leaked via a binder stub. + Fix: https://cs.android.com/android/_/android/platform/frameworks/base/+/0796e9fb3dc2dd03fa5ff2053c63f14861cffa2f + """.trimIndent() + ) { sdkInt < 24 } + } + }, + + DREAM_SERVICE { + override fun add(references: MutableList) { + AndroidReferenceMatchers.nativeGlobalVariableLeak( + className = "android.service.dreams.DreamService\$1", + description = """ + DreamService leaks a binder stub. + https://github.com/square/leakcanary/issues/2534 + """.trimIndent() + ) { sdkInt >= 33 } + } + }, + // ######## Manufacturer specific known leaks ######## // SAMSUNG @@ -1319,15 +1375,15 @@ enum class AndroidReferenceMatchers { override fun add( references: MutableList ) { - references += staticFieldLeak( - "android.app.ExtendedStatusBarManager", "sInstance", + references += instanceFieldLeak( + "android.app.ExtendedStatusBarManager", "mContext", description = """ - ExtendedStatusBarManager is held in a static sInstance field and has a mContext - field which references a decor context which references a destroyed activity. + ExtendedStatusBarManager has a mContext field which references a decor context which + references a destroyed activity. """.trimIndent() ) { - manufacturer == SHARP && sdkInt == 30 + manufacturer == SHARP && sdkInt >= 30 } } }, @@ -1381,6 +1437,20 @@ enum class AndroidReferenceMatchers { } }, + XIAMI__RESOURCES_IMPL { + override fun add(references: MutableList) { + references += staticFieldLeak( + "android.content.res.ResourcesImpl", "mAppContext", + description = """ + Both Nokia & Xiaomi added a static mAppContext field to the ResourcesImpl class and + that field ends up referencing lower contexts (e.g. service). + """.trimIndent() + ) { + (manufacturer == XIAOMI || manufacturer == HMD_GLOBAL) && sdkInt >= 30 + } + } + }, + // ######## Ignored references (not leaks) ######## REFERENCES { @@ -1479,6 +1549,8 @@ enum class AndroidReferenceMatchers { const val VIVO = "vivo" const val RAZER = "Razer" const val SHARP = "SHARP" + const val XIAOMI = "Xiaomi" + const val HMD_GLOBAL = "HMD Global" /** * Returns a list of [ReferenceMatcher] that only contains [IgnoredReferenceMatcher] and no