Repository: square/leakcanary
Issue: ServiceNotFoundException for input_method

### Description
Rare crash on Galaxy S8+ with Android 8.0.0 as follows
```
Caused by android.os.ServiceManager$ServiceNotFoundException: No service published for: input_method
       at android.os.ServiceManager.getServiceOrThrow(ServiceManager.java:85)
       at android.view.inputmethod.InputMethodManager.<init>(InputMethodManager.java:720)
       at android.view.inputmethod.InputMethodManager.getInstance(InputMethodManager.java:806)
       at android.app.SystemServiceRegistry$24.createService(SystemServiceRegistry.java:478)
       at android.app.SystemServiceRegistry$24.createService(SystemServiceRegistry.java:476)
       at android.app.SystemServiceRegistry$StaticServiceFetcher.getService(SystemServiceRegistry.java:1399)
       at android.app.SystemServiceRegistry.getSystemService(SystemServiceRegistry.java:1326)
       at android.app.ContextImpl.getSystemService(ContextImpl.java:1695)
       at android.content.ContextWrapper.getSystemService(ContextWrapper.java:727)
       at leakcanary.AndroidLeakFixes$IMM_CUR_ROOT_VIEW.apply(AndroidLeakFixes.java:489)
       at leakcanary.AndroidLeakFixes$Companion.applyFixes(AndroidLeakFixes.java:684)
       at leakcanary.AndroidLeakFixes$Companion.applyFixes$default(AndroidLeakFixes.java:679)
       at leakcanary.internal.PlumberInstaller.onCreate(PlumberInstaller.java:18)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1925)
       at android.content.ContentProvider.attachInfo(ContentProvider.java:1900)
       at android.app.ActivityThread.installProvider(ActivityThread.java:6572)
       at android.app.ActivityThread.installContentProviders(ActivityThread.java:6127)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6037)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
       at android.os.Handler.dispatchMessage(Handler.java:105)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6938)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
```

### Version Information

* LeakCanary version: 2.7
* Android OS version: 8.0.0
* Gradle version: 7.1


Changed files:
plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt

diff --git a/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt b/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt
index 90ee97be4..650f02a8a 100644
--- a/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt
+++ b/plumber-android-core/src/main/java/leakcanary/AndroidLeakFixes.kt
@@ -484,14 +484,18 @@ enum class AndroidLeakFixes {
       if (SDK_INT >= 29) {
         return
       }
-      val inputMethodManager =
+      val inputMethodManager = try {
         application.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
-      val mCurRootViewField: Field
-      try {
-        mCurRootViewField =
-          InputMethodManager::class.java.getDeclaredField("mCurRootView")
-        mCurRootViewField.isAccessible = true
-      } catch (ignored: Exception) {
+      } catch (ignored: Throwable) {
+        // https://github.com/square/leakcanary/issues/2140
+        SharkLog.d(ignored) { "Could not retrieve InputMethodManager service" }
+        return
+      }
+      val mCurRootViewField = try {
+          InputMethodManager::class.java.getDeclaredField("mCurRootView").apply {
+            isAccessible = true
+          }
+      } catch (ignored: Throwable) {
         SharkLog.d(ignored) { "Could not read InputMethodManager.mCurRootView field" }
         return
       }
@@ -504,7 +508,7 @@ enum class AndroidLeakFixes {
             ) {
               mCurRootViewField[inputMethodManager] = null
             }
-          } catch (ignored: Exception) {
+          } catch (ignored: Throwable) {
             SharkLog.d(ignored) { "Could not update InputMethodManager.mCurRootView field" }
           }
         }