From 0434a4332f69049874cf492dd6d4f74a19bdf531 Mon Sep 17 00:00:00 2001 From: "auto-submit[bot]" <98614782+auto-submit[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:32:48 +0000 Subject: [PATCH] Reverts "Replace `WindowInsetsController...` with `adb shell` commands (#51843)" (flutter/engine#51847) Reverts: flutter/engine#51843 Initiated by: matanlurey Reason for reverting: broke tree because the bottom bar now shows up. Original PR Author: matanlurey Reviewed By: {jonahwilliams} This change reverts the following previous change: Previously our screenshots looked like this (when they ran correctly): ![image](https://github.com/flutter/engine/assets/168174/14d46a7a-9b60-4c5d-b786-a6cbee823ef9) Now, sometimes (only on CI unfortunately) they look like this: ![image](https://github.com/flutter/engine/assets/168174/f4e49258-dcde-4864-b622-19c36c52f8b7) This started happening after https://github.com/flutter/engine/pull/51832, but the change should be future-proof as well even if we disable the screen recording feature. h/t @reidbaker --- .../dev/flutter/scenarios/TestActivity.java | 14 ++++++++++ .../scenario_app/bin/run_android_tests.dart | 28 ++++++++----------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TestActivity.java b/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TestActivity.java index 5249577869..c3b8b31e1e 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TestActivity.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/TestActivity.java @@ -9,8 +9,12 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.view.Window; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.view.WindowInsetsControllerCompat; import io.flutter.FlutterInjector; import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.loader.FlutterLoader; @@ -25,6 +29,7 @@ public abstract class TestActivity extends TestableFlutterActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + hideSystemBars(getWindow()); testFlutterLoaderCallbackWhenInitializedTwice(); } @@ -104,4 +109,13 @@ public abstract class TestActivity extends TestableFlutterActivity { } }); } + + private static void hideSystemBars(Window window) { + final WindowInsetsControllerCompat insetController = + WindowCompat.getInsetsController(window, window.getDecorView()); + assert insetController != null; + insetController.setSystemBarsBehavior( + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); + insetController.hide(WindowInsetsCompat.Type.systemBars()); + } } diff --git a/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart b/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart index 5629eb7fd6..a4782f31cf 100644 --- a/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart +++ b/engine/src/flutter/testing/scenario_app/bin/run_android_tests.dart @@ -298,23 +298,17 @@ Future _run({ }); await step('Configuring emulator...', () async { - final List> adbShellCommands = > [ - // Try to close all OS popups in the emulator, like "System UI stopped working". - ['am', 'broadcast', '-a', 'android.intent.action.CLOSE_SYSTEM_DIALOGS'], - - // Don't show "this is how you exit fullscreen mode". - ['settings', 'put', 'secure', 'immersive_mode_confirmations', 'confirmed'], - - // Hide all system bars. - ['settings', 'put', 'global', 'policy_control', 'immersive.full=*'], - ]; - - // Run all the commands. - for (final List command in adbShellCommands) { - final int exitCode = await pm.runAndForward([adb.path, 'shell', ...command]); - if (exitCode != 0) { - panic(['could not run command: ${command.join(' ')}']); - } + final int exitCode = await pm.runAndForward([ + adb.path, + 'shell', + 'settings', + 'put', + 'secure', + 'immersive_mode_confirmations', + 'confirmed', + ]); + if (exitCode != 0) { + panic(['could not configure emulator']); } });