Repository: square/leakcanary
Issue: Before API 19, watch detached root views not working

### Description

* Before API 17:

``` java
12-11 10:39:54.740 5189-5189/? D/LeakCanary: Could not watch detached root views
    java.lang.ClassNotFoundException: android.view.WindowManagerGlobal
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:217)
        at java.lang.Class.forName(Class.java:172)
        at leakcanary.internal.RootViewDetachWatcher$Companion.install(RootViewDetachWatcher.kt:55)
        at leakcanary.internal.InternalAppWatcher.install(InternalAppWatcher.kt:79)
        at leakcanary.AppWatcher.manualInstall(AppWatcher.kt:230)
        at leakcanary.internal.AppWatcherInstaller.onCreate(AppWatcherInstaller.kt:29)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
        at android.app.ActivityThread.installProvider(ActivityThread.java:4560)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:4190)
```

### Steps to Reproduce

1. Run sample

**Expected behavior:** Work perfectly before API 19

### Version Information

* LeakCanary version: main branch
* Android OS version: 4.1.1, 4.0.3
* Gradle version: 6.5

### Additional Information

* `WindowManagerGlobal` added by API 17, but `mViews` still array before API 19.
* Before API 19, `mViews` is a `View[]`. That means we can not make a sub class of `ArrayList` and override `add` method to handle `root view added` event.
* ~~(__Maybe a solution__) Hook `WindowManagerImpl.sWindowManager` and set a dynamic proxy to it. Then track the call of [void addView(View view, ViewGroup.LayoutParams params, CompatibilityInfoHolder cih, boolean nest)](https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-4.1.2_r2.1/core/java/android/view/WindowManagerImpl.java#227). When addView is invoked, we can notify that the root view(the first parameter of `addView`) has been added.~~

Changed files:
leakcanary-object-watcher-android/src/main/java/leakcanary/RootViewWatcher.kt

diff --git a/leakcanary-object-watcher-android/src/main/java/leakcanary/RootViewWatcher.kt b/leakcanary-object-watcher-android/src/main/java/leakcanary/RootViewWatcher.kt
index 7899fb1be..e414ba8a0 100644
--- a/leakcanary-object-watcher-android/src/main/java/leakcanary/RootViewWatcher.kt
+++ b/leakcanary-object-watcher-android/src/main/java/leakcanary/RootViewWatcher.kt
@@ -16,6 +16,7 @@
 package leakcanary
 
 import android.annotation.SuppressLint
+import android.os.Build
 import android.view.View
 import android.view.View.OnAttachStateChangeListener
 import leakcanary.internal.mainHandler
@@ -30,6 +31,9 @@ class RootViewWatcher(
 ) : InstallableWatcher {
 
   override fun install() {
+    if (Build.VERSION.SDK_INT < 19) {
+      return
+    }
     swapViewManagerGlobalMViews { mViews ->
       object : ArrayList<View>(mViews) {
         override fun add(element: View): Boolean {
@@ -41,6 +45,9 @@ class RootViewWatcher(
   }
 
   override fun uninstall() {
+    if (Build.VERSION.SDK_INT < 19) {
+      return
+    }
     swapViewManagerGlobalMViews { mViews ->
       ArrayList(mViews)
     }