Flutter Engine
The Flutter Engine
TestableFlutterActivity.java
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package dev.flutter.scenarios;
6
7import android.os.Bundle;
8import android.view.WindowManager;
9import androidx.annotation.NonNull;
10import androidx.annotation.Nullable;
11import io.flutter.embedding.android.FlutterActivity;
12import io.flutter.embedding.engine.FlutterEngine;
13import java.util.concurrent.CountDownLatch;
14
15public abstract class TestableFlutterActivity extends FlutterActivity {
16 private final CountDownLatch flutterUiRenderedLatch = new CountDownLatch(1);
17
18 @Override
19 public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
20 // Do not call super. We have no plugins to register, and the automatic
21 // registration will fail and print a scary exception in the logs.
22 flutterEngine
23 .getDartExecutor()
24 .setMessageHandler("take_screenshot", (byteBuffer, binaryReply) -> notifyFlutterRendered());
25 }
26
27 @Override
28 protected void onCreate(@Nullable Bundle savedInstanceState) {
29 super.onCreate(savedInstanceState);
30
31 // On newer versions of Android, this is the default. Because these tests are being used to take
32 // screenshots on Skia Gold, we don't want any of the System UI to show up, even for older API
33 // versions (i.e. 28).
34 //
35 // See also:
36 // https://github.com/flutter/engine/blob/a9081cce1f0dd730577a36ee1ca6d7af5cdc5a9b/shell/platform/android/io/flutter/embedding/android/FlutterView.java#L696
37 // https://github.com/flutter/flutter/issues/143471
38 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
39 }
40
41 protected void notifyFlutterRendered() {
42 flutterUiRenderedLatch.countDown();
43 }
44
46 try {
47 flutterUiRenderedLatch.await();
48 } catch (InterruptedException e) {
49 throw new RuntimeException(e);
50 }
51 }
52}
void configureFlutterEngine(@NonNull FlutterEngine flutterEngine)
void onCreate(@Nullable Bundle savedInstanceState)