From 6969c285f3f58e1d258dec2115c3f44c6a2e910b Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 1 Apr 2024 11:06:52 -0700 Subject: [PATCH] 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. --- .../android/app/src/main/AndroidManifest.xml | 5 - .../dev/flutter/scenarios/TestActivity.java | 98 ++----------------- .../testing/scenario_app/lib/main.dart | 32 ------ 3 files changed, 6 insertions(+), 129 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/main/AndroidManifest.xml b/engine/src/flutter/testing/scenario_app/android/app/src/main/AndroidManifest.xml index e125978054..e6b25eaecd 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/main/AndroidManifest.xml +++ b/engine/src/flutter/testing/scenario_app/android/app/src/main/AndroidManifest.xml @@ -18,11 +18,6 @@ android:launchMode="singleTop" android:windowSoftInputMode="adjustResize" android:exported="true"> - - - - - 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 03fdbeee31..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 @@ -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 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 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."); } }); } diff --git a/engine/src/flutter/testing/scenario_app/lib/main.dart b/engine/src/flutter/testing/scenario_app/lib/main.dart index 080959becc..2dfd2c2125 100644 --- a/engine/src/flutter/testing/scenario_app/lib/main.dart +++ b/engine/src/flutter/testing/scenario_app/lib/main.dart @@ -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 _handleWriteTimelineMessage(ByteData? data, PlatformMessageResponseCallback? callback) async { - final String timelineData = await _getTimelineData(); - callback!(ByteData.sublistView(utf8.encode(timelineData))); -} - -Future _getTimelineData() async { - final developer.ServiceProtocolInfo info = await developer.Service.getInfo(); - final Uri vmServiceTimelineUri = info.serverUri!.resolve('getVMTimeline'); - final Map vmServiceTimelineJson = await _getJson(vmServiceTimelineUri); - final Map vmServiceResult = vmServiceTimelineJson['result'] as Map; - return json.encode({ - 'traceEvents': [ - ...vmServiceResult['traceEvents'] as List, - ], - }); -} - -Future> _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 {}; - } - final String data = await utf8.decodeStream(response); - return json.decode(data) as Map; -} - void _onBeginFrame(Duration duration) { // Render an empty frame to signal first frame in the platform side. if (currentScenario == null) {