From 6702225841a50ca0318ecc81ca5e944266fea066 Mon Sep 17 00:00:00 2001 From: GeorgCantor Date: Mon, 23 Sep 2024 15:14:33 +0300 Subject: [PATCH] Update AndroidLeakFixes.kt --- .../main/java/leakcanary/AndroidLeakFixes.kt | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/plumber/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt b/plumber/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt index f223ad44b4..a9fd8c4553 100644 --- a/plumber/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt +++ b/plumber/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt @@ -539,25 +539,14 @@ enum class AndroidLeakFixes { private val Context.activityOrNull: Activity? get() { var context = this - while (true) { - if (context is Application) { - return null - } - if (context is Activity) { - return context - } - if (context is ContextWrapper) { - val baseContext = context.baseContext - // Prevent Stack Overflow. - if (baseContext === this) { - return null + while (context is ContextWrapper) { + if (context is Activity) { + return context } - context = baseContext - } else { - return null - } + context = context.baseContext } - } + return if (context is Activity) context else null + } }, /**