Remove unused and untested timeline data branch for scenario_app (flutter/engine#51816)

All of this appears to be completely unused and untested, and I don't see value in fixing it.
This commit is contained in:
Matan Lurey
2024-04-01 11:06:52 -07:00
committed by GitHub
parent e6b41a1754
commit 6969c285f3
3 changed files with 6 additions and 129 deletions

View File

@@ -18,11 +18,6 @@
android:launchMode="singleTop"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="com.google.intent.action.TEST_LOOP" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/javascript" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@@ -4,14 +4,8 @@
package dev.flutter.scenarios;
import static io.flutter.Build.API_LEVELS;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -22,56 +16,25 @@ import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import io.flutter.FlutterInjector;
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.BinaryCodec;
import io.flutter.plugin.common.JSONMethodCodec;
import io.flutter.plugin.common.MethodChannel;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
public abstract class TestActivity extends TestableFlutterActivity {
static final String TAG = "Scenarios";
private final Runnable resultsTask =
new Runnable() {
@Override
public void run() {
final Uri logFileUri = getIntent().getData();
writeTimelineData(logFileUri);
testFlutterLoaderCallbackWhenInitializedTwice();
}
};
private final Handler handler = new Handler();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideSystemBars(getWindow());
final Intent launchIntent = getIntent();
if ("com.google.intent.action.TEST_LOOP".equals(launchIntent.getAction())) {
if (Build.VERSION.SDK_INT > API_LEVELS.API_22) {
requestPermissions(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
handler.postDelayed(resultsTask, 20000);
} else {
testFlutterLoaderCallbackWhenInitializedTwice();
}
testFlutterLoaderCallbackWhenInitializedTwice();
}
@Override
protected void onDestroy() {
handler.removeCallbacks(resultsTask);
super.onDestroy();
}
@@ -115,44 +78,6 @@ public abstract class TestActivity extends TestableFlutterActivity {
*/
protected void getScenarioParams(@NonNull Map<String, Object> args) {}
protected void writeTimelineData(@Nullable Uri logFile) {
if (logFile == null) {
throw new IllegalArgumentException();
}
if (getFlutterEngine() == null) {
Log.e(TAG, "Could not write timeline data - no engine.");
return;
}
final BasicMessageChannel<ByteBuffer> channel =
new BasicMessageChannel<>(
getFlutterEngine().getDartExecutor(), "write_timeline", BinaryCodec.INSTANCE);
channel.send(
null,
(ByteBuffer reply) -> {
AssetFileDescriptor afd = null;
try {
afd = getContentResolver().openAssetFileDescriptor(logFile, "w");
assert afd != null;
final FileDescriptor fd = afd.getFileDescriptor();
final FileOutputStream outputStream = new FileOutputStream(fd);
assert reply != null;
outputStream.write(reply.array());
outputStream.close();
} catch (IOException ex) {
Log.e(TAG, "Could not write timeline file", ex);
} finally {
try {
if (afd != null) {
afd.close();
}
} catch (IOException e) {
Log.w(TAG, "Could not close", e);
}
}
finish();
});
}
/**
* This method verifies that {@link
* io.flutter.embedding.engine.loader.FlutterLoader#ensureInitializationCompleteAsync(Context,
@@ -174,24 +99,13 @@ public abstract class TestActivity extends TestableFlutterActivity {
final AtomicBoolean didInvokeCallback = new AtomicBoolean(false);
flutterLoader.ensureInitializationCompleteAsync(
getApplication(),
new String[] {},
mainHandler,
new Runnable() {
@Override
public void run() {
didInvokeCallback.set(true);
}
});
getApplication(), new String[] {}, mainHandler, () -> didInvokeCallback.set(true));
mainHandler.post(
new Runnable() {
@Override
public void run() {
if (!didInvokeCallback.get()) {
throw new RuntimeException(
"Failed test: FlutterLoader#ensureInitializationCompleteAsync() did not invoke its callback.");
}
() -> {
if (!didInvokeCallback.get()) {
throw new RuntimeException(
"Failed test: FlutterLoader#ensureInitializationCompleteAsync() did not invoke its callback.");
}
});
}

View File

@@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:developer' as developer;
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
@@ -23,7 +20,6 @@ void main() {
..onPointerDataPacket = _onPointerDataPacket
..scheduleFrame();
channelBuffers.setListener('driver', _handleDriverMessage);
channelBuffers.setListener('write_timeline', _handleWriteTimelineMessage);
final FlutterView view = PlatformDispatcher.instance.implicitView!;
// Asserting that this is greater than zero since this app runs on different
@@ -54,34 +50,6 @@ void _handleDriverMessage(ByteData? data, PlatformMessageResponseCallback? callb
}
}
Future<void> _handleWriteTimelineMessage(ByteData? data, PlatformMessageResponseCallback? callback) async {
final String timelineData = await _getTimelineData();
callback!(ByteData.sublistView(utf8.encode(timelineData)));
}
Future<String> _getTimelineData() async {
final developer.ServiceProtocolInfo info = await developer.Service.getInfo();
final Uri vmServiceTimelineUri = info.serverUri!.resolve('getVMTimeline');
final Map<String, dynamic> vmServiceTimelineJson = await _getJson(vmServiceTimelineUri);
final Map<String, dynamic> vmServiceResult = vmServiceTimelineJson['result'] as Map<String, dynamic>;
return json.encode(<String, dynamic>{
'traceEvents': <dynamic>[
...vmServiceResult['traceEvents'] as List<dynamic>,
],
});
}
Future<Map<String, dynamic>> _getJson(Uri uri) async {
final HttpClient client = HttpClient();
final HttpClientRequest request = await client.getUrl(uri);
final HttpClientResponse response = await request.close();
if (response.statusCode > 299) {
return <String, dynamic>{};
}
final String data = await utf8.decodeStream(response);
return json.decode(data) as Map<String, dynamic>;
}
void _onBeginFrame(Duration duration) {
// Render an empty frame to signal first frame in the platform side.
if (currentScenario == null) {