In the scenario game loop test, cancel the results writer task if the activity has been destroyed (flutter/engine#48051)

This test is run on Firebase Test Lab, and crashes have been reported on CI if this task executes when the activity is in a destroyed state.

See https://github.com/flutter/flutter/issues/138451
This commit is contained in:
Jason Simmons
2023-11-15 09:10:49 -08:00
committed by GitHub
parent c4e4fb0c9e
commit a9c9177d35

View File

@@ -37,6 +37,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
public abstract class TestActivity extends TestableFlutterActivity {
static final String TAG = "Scenarios";
private Runnable resultsTask =
new Runnable() {
@Override
public void run() {
final Uri logFileUri = getIntent().getData();
writeTimelineData(logFileUri);
testFlutterLoaderCallbackWhenInitializedTwice();
}
};
private Handler handler = new Handler();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -47,22 +59,18 @@ public abstract class TestActivity extends TestableFlutterActivity {
if (Build.VERSION.SDK_INT > 22) {
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
final Uri logFileUri = launchIntent.getData();
new Handler()
.postDelayed(
new Runnable() {
@Override
public void run() {
writeTimelineData(logFileUri);
testFlutterLoaderCallbackWhenInitializedTwice();
}
},
20000);
handler.postDelayed(resultsTask, 20000);
} else {
testFlutterLoaderCallbackWhenInitializedTwice();
}
}
@Override
protected void onDestroy() {
handler.removeCallbacks(resultsTask);
super.onDestroy();
}
@Override
@NonNull
public FlutterShellArgs getFlutterShellArgs() {