From f872f6922d36c88595e8fa78f42b53c50eada5d6 Mon Sep 17 00:00:00 2001
From: Tiger <tigerhuang@google.com>
Date: Wed, 10 Apr 2024 23:03:26 +0800
Subject: [PATCH] Add proper padding to PerfTestActivity

Since Android V, apps targeting SDK 35+ will be forced to go
edge-to-edge. This CL adds proper padding to the content view of
PerfTestActivity, so the EditText within it won't be obscured by system
bars. Otherwise, there would be unexpected scrolling while showing or
hiding IME.

This CL also removes the action bar from the activity, so that the
content won't be obscured by it.

Fix: 331025926
Bug: 309578419
Flag: com.android.window.flags.enforce_edge_to_edge
Test: ImePerfTest
Change-Id: I212ef4862b4249e288267fb8fb4448b9100107c1
---
 apct-tests/perftests/inputmethod/AndroidManifest.xml       | 3 ++-
 .../src/android/perftests/utils/PerfTestActivity.java      | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/apct-tests/perftests/inputmethod/AndroidManifest.xml b/apct-tests/perftests/inputmethod/AndroidManifest.xml
index 3eea418fe5c7..5dd6ccccfb1c 100644
--- a/apct-tests/perftests/inputmethod/AndroidManifest.xml
+++ b/apct-tests/perftests/inputmethod/AndroidManifest.xml
@@ -22,7 +22,8 @@
     <application>
         <uses-library android:name="android.test.runner" />
         <activity android:name="android.perftests.utils.PerfTestActivity"
-            android:exported="true">
+                  android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
+                  android:exported="true">
           <intent-filter>
             <action android:name="com.android.perftests.core.PERFTEST" />
           </intent-filter>
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/PerfTestActivity.java b/apct-tests/perftests/utils/src/android/perftests/utils/PerfTestActivity.java
index f3bea17b2f0d..0c2ee8cb238a 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/PerfTestActivity.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/PerfTestActivity.java
@@ -19,7 +19,9 @@ package android.perftests.utils;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.graphics.Insets;
 import android.os.Bundle;
+import android.view.WindowInsets;
 import android.view.WindowManager;
 import android.widget.EditText;
 import android.widget.LinearLayout;
@@ -42,6 +44,11 @@ public class PerfTestActivity extends Activity {
         if (getIntent().getBooleanExtra(INTENT_EXTRA_ADD_EDIT_TEXT, false)) {
             final LinearLayout layout = new LinearLayout(this);
             layout.setOrientation(LinearLayout.VERTICAL);
+            layout.setOnApplyWindowInsetsListener((v, w) -> {
+                final Insets insets = w.getSystemWindowInsets();
+                v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+                return WindowInsets.CONSUMED;
+            });
 
             final EditText editText = new EditText(this);
             editText.setId(ID_EDITOR);
-- 
GitLab