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
This commit is contained in:
auto-submit[bot]
2024-04-02 19:32:48 +00:00
committed by GitHub
parent e124b252ae
commit 0434a4332f
2 changed files with 25 additions and 17 deletions

View File

@@ -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());
}
}

View File

@@ -298,23 +298,17 @@ Future<void> _run({
});
await step('Configuring emulator...', () async {
final List<List<String>> adbShellCommands = <List<String>> [
// Try to close all OS popups in the emulator, like "System UI stopped working".
<String>['am', 'broadcast', '-a', 'android.intent.action.CLOSE_SYSTEM_DIALOGS'],
// Don't show "this is how you exit fullscreen mode".
<String>['settings', 'put', 'secure', 'immersive_mode_confirmations', 'confirmed'],
// Hide all system bars.
<String>['settings', 'put', 'global', 'policy_control', 'immersive.full=*'],
];
// Run all the commands.
for (final List<String> command in adbShellCommands) {
final int exitCode = await pm.runAndForward(<String>[adb.path, 'shell', ...command]);
if (exitCode != 0) {
panic(<String>['could not run command: ${command.join(' ')}']);
}
final int exitCode = await pm.runAndForward(<String>[
adb.path,
'shell',
'settings',
'put',
'secure',
'immersive_mode_confirmations',
'confirmed',
]);
if (exitCode != 0) {
panic(<String>['could not configure emulator']);
}
});