Add the max height restriction into the illustration view.

Bug: 191721423
Test: manual test
Change-Id: I3829ead500eaf586f6d543855690ee8f0d0913ff
diff --git a/src/com/android/settings/accessibility/AccessibilityUtil.java b/src/com/android/settings/accessibility/AccessibilityUtil.java
index 5c316a4..c935956 100644
--- a/src/com/android/settings/accessibility/AccessibilityUtil.java
+++ b/src/com/android/settings/accessibility/AccessibilityUtil.java
@@ -17,16 +17,22 @@
 package com.android.settings.accessibility;
 
 import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
+import static android.view.WindowInsets.Type.displayCutout;
+import static android.view.WindowInsets.Type.systemBars;
 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Insets;
+import android.graphics.Rect;
 import android.os.Build;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.util.TypedValue;
+import android.view.WindowManager;
+import android.view.WindowMetrics;
 import android.view.accessibility.AccessibilityManager;
 
 import androidx.annotation.IntDef;
@@ -391,6 +397,25 @@
     }
 
     /**
+     * Gets the bounds of the display window excluding the insets of the system bar and display
+     * cut out.
+     *
+     * @param context the current context.
+     * @return the bounds of the display window.
+     */
+    public static Rect getDisplayBounds(Context context) {
+        final WindowManager windowManager = context.getSystemService(WindowManager.class);
+        final WindowMetrics metrics = windowManager.getCurrentWindowMetrics();
+
+        final Rect displayBounds = metrics.getBounds();
+        final Insets displayInsets = metrics.getWindowInsets().getInsetsIgnoringVisibility(
+                systemBars() | displayCutout());
+        displayBounds.inset(displayInsets);
+
+        return displayBounds;
+    }
+
+    /**
      * Indicates if the accessibility service belongs to a system App.
      * @param info AccessibilityServiceInfo
      * @return {@code true} if the App is a system App.
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index 245f362..4f45b03 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -406,10 +406,13 @@
             return;
         }
 
+        final int displayHalfHeight =
+                AccessibilityUtil.getDisplayBounds(getPrefContext()).height() / 2;
         final IllustrationPreference illustrationPreference =
                 new IllustrationPreference(getPrefContext());
         illustrationPreference.setImageUri(mImageUri);
         illustrationPreference.setSelectable(false);
+        illustrationPreference.setMaxHeight(displayHalfHeight);
         illustrationPreference.setKey(KEY_ANIMATED_IMAGE);
 
         getPreferenceScreen().addPreference(illustrationPreference);