Make tracing safe (flutter/engine#32042)
This commit is contained in:
@@ -1281,6 +1281,7 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/platform/Platfor
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Preconditions.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/Predicate.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/TraceSection.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/util/ViewUtils.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/view/AccessibilityViewEmbedder.java
|
||||
|
||||
@@ -276,6 +276,7 @@ android_java_sources = [
|
||||
"io/flutter/util/PathUtils.java",
|
||||
"io/flutter/util/Preconditions.java",
|
||||
"io/flutter/util/Predicate.java",
|
||||
"io/flutter/util/TraceSection.java",
|
||||
"io/flutter/util/ViewUtils.java",
|
||||
"io/flutter/view/AccessibilityBridge.java",
|
||||
"io/flutter/view/AccessibilityViewEmbedder.java",
|
||||
|
||||
@@ -14,7 +14,6 @@ import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.tracing.Trace;
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.android.ExclusiveAppComponent;
|
||||
import io.flutter.embedding.engine.loader.FlutterLoader;
|
||||
@@ -33,6 +32,7 @@ import io.flutter.embedding.engine.plugins.lifecycle.HiddenLifecycleReference;
|
||||
import io.flutter.embedding.engine.plugins.service.ServiceAware;
|
||||
import io.flutter.embedding.engine.plugins.service.ServiceControlSurface;
|
||||
import io.flutter.embedding.engine.plugins.service.ServicePluginBinding;
|
||||
import io.flutter.util.TraceSection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -123,8 +123,7 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void add(@NonNull FlutterPlugin plugin) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#add " + plugin.getClass().getSimpleName());
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#add " + plugin.getClass().getSimpleName());
|
||||
try {
|
||||
if (has(plugin.getClass())) {
|
||||
Log.w(
|
||||
@@ -192,7 +191,7 @@ import java.util.Set;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,10 +219,8 @@ import java.util.Set;
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#remove " + pluginClass.getSimpleName());
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#remove " + pluginClass.getSimpleName());
|
||||
try {
|
||||
Log.v(TAG, "Removing plugin: " + plugin);
|
||||
// For ActivityAware plugins, notify the plugin that it is detached from
|
||||
// an Activity if an Activity is currently attached to this engine. Then
|
||||
// remove the plugin from our set of ActivityAware plugins.
|
||||
@@ -273,7 +270,7 @@ import java.util.Set;
|
||||
plugin.onDetachedFromEngine(pluginBinding);
|
||||
plugins.remove(pluginClass);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,16 +313,8 @@ import java.util.Set;
|
||||
@Override
|
||||
public void attachToActivity(
|
||||
@NonNull ExclusiveAppComponent<Activity> exclusiveActivity, @NonNull Lifecycle lifecycle) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#attachToActivity");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#attachToActivity");
|
||||
try {
|
||||
Log.v(
|
||||
TAG,
|
||||
"Attaching to an exclusive Activity: "
|
||||
+ exclusiveActivity.getAppComponent()
|
||||
+ (isAttachedToActivity() ? " evicting previous activity " + attachedActivity() : "")
|
||||
+ "."
|
||||
+ (isWaitingForActivityReattachment ? " This is after a config change." : ""));
|
||||
if (this.exclusiveActivity != null) {
|
||||
this.exclusiveActivity.detachFromFlutterEngine();
|
||||
}
|
||||
@@ -334,7 +323,7 @@ import java.util.Set;
|
||||
this.exclusiveActivity = exclusiveActivity;
|
||||
attachToActivityInternal(exclusiveActivity.getAppComponent(), lifecycle);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,9 +351,7 @@ import java.util.Set;
|
||||
@Override
|
||||
public void detachFromActivityForConfigChanges() {
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#detachFromActivityForConfigChanges");
|
||||
Log.v(TAG, "Detaching from an Activity for config changes: " + attachedActivity());
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#detachFromActivityForConfigChanges");
|
||||
try {
|
||||
isWaitingForActivityReattachment = true;
|
||||
|
||||
@@ -374,7 +361,7 @@ import java.util.Set;
|
||||
|
||||
detachFromActivityInternal();
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Attempted to detach plugins from an Activity when no Activity was attached.");
|
||||
@@ -384,17 +371,15 @@ import java.util.Set;
|
||||
@Override
|
||||
public void detachFromActivity() {
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#detachFromActivity");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#detachFromActivity");
|
||||
try {
|
||||
Log.v(TAG, "Detaching from an Activity: " + attachedActivity());
|
||||
for (ActivityAware activityAware : activityAwarePlugins.values()) {
|
||||
activityAware.onDetachedFromActivity();
|
||||
}
|
||||
|
||||
detachFromActivityInternal();
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Attempted to detach plugins from an Activity when no Activity was attached.");
|
||||
@@ -412,15 +397,13 @@ import java.util.Set;
|
||||
@Override
|
||||
public boolean onRequestPermissionsResult(
|
||||
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResult) {
|
||||
Log.v(TAG, "Forwarding onRequestPermissionsResult() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onRequestPermissionsResult");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onRequestPermissionsResult");
|
||||
try {
|
||||
return activityPluginBinding.onRequestPermissionsResult(
|
||||
requestCode, permissions, grantResult);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -433,14 +416,12 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
Log.v(TAG, "Forwarding onActivityResult() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onActivityResult");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onActivityResult");
|
||||
try {
|
||||
return activityPluginBinding.onActivityResult(requestCode, resultCode, data);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -453,14 +434,12 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void onNewIntent(@NonNull Intent intent) {
|
||||
Log.v(TAG, "Forwarding onNewIntent() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onNewIntent");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onNewIntent");
|
||||
try {
|
||||
activityPluginBinding.onNewIntent(intent);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -472,14 +451,12 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void onUserLeaveHint() {
|
||||
Log.v(TAG, "Forwarding onUserLeaveHint() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onUserLeaveHint");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onUserLeaveHint");
|
||||
try {
|
||||
activityPluginBinding.onUserLeaveHint();
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -491,14 +468,12 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle bundle) {
|
||||
Log.v(TAG, "Forwarding onSaveInstanceState() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onSaveInstanceState");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onSaveInstanceState");
|
||||
try {
|
||||
activityPluginBinding.onSaveInstanceState(bundle);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -510,14 +485,12 @@ import java.util.Set;
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(@Nullable Bundle bundle) {
|
||||
Log.v(TAG, "Forwarding onRestoreInstanceState() to plugins.");
|
||||
if (isAttachedToActivity()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onRestoreInstanceState");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onRestoreInstanceState");
|
||||
try {
|
||||
activityPluginBinding.onRestoreInstanceState(bundle);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -536,9 +509,7 @@ import java.util.Set;
|
||||
@Override
|
||||
public void attachToService(
|
||||
@NonNull Service service, @Nullable Lifecycle lifecycle, boolean isForeground) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#attachToService");
|
||||
Log.v(TAG, "Attaching to a Service: " + service);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#attachToService");
|
||||
try {
|
||||
// If we were already attached to an Android component, detach from it.
|
||||
detachFromAppComponent();
|
||||
@@ -551,16 +522,14 @@ import java.util.Set;
|
||||
serviceAware.onAttachedToService(servicePluginBinding);
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachFromService() {
|
||||
if (isAttachedToService()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#detachFromService");
|
||||
Log.v(TAG, "Detaching from a Service: " + service);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#detachFromService");
|
||||
try {
|
||||
// Notify all ServiceAware plugins that they are no longer attached to a Service.
|
||||
for (ServiceAware serviceAware : serviceAwarePlugins.values()) {
|
||||
@@ -570,7 +539,7 @@ import java.util.Set;
|
||||
service = null;
|
||||
servicePluginBinding = null;
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Attempted to detach plugins from a Service when no Service was attached.");
|
||||
@@ -580,13 +549,11 @@ import java.util.Set;
|
||||
@Override
|
||||
public void onMoveToForeground() {
|
||||
if (isAttachedToService()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onMoveToForeground");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onMoveToForeground");
|
||||
try {
|
||||
Log.v(TAG, "Attached Service moved to foreground.");
|
||||
servicePluginBinding.onMoveToForeground();
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -594,13 +561,12 @@ import java.util.Set;
|
||||
@Override
|
||||
public void onMoveToBackground() {
|
||||
if (isAttachedToService()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#onMoveToBackground");
|
||||
Log.v(TAG, "Attached Service moved to background.");
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#onMoveToBackground");
|
||||
;
|
||||
try {
|
||||
servicePluginBinding.onMoveToBackground();
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,9 +580,7 @@ import java.util.Set;
|
||||
@Override
|
||||
public void attachToBroadcastReceiver(
|
||||
@NonNull BroadcastReceiver broadcastReceiver, @NonNull Lifecycle lifecycle) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#attachToBroadcastReceiver");
|
||||
Log.v(TAG, "Attaching to BroadcastReceiver: " + broadcastReceiver);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#attachToBroadcastReceiver");
|
||||
try {
|
||||
// If we were already attached to an Android component, detach from it.
|
||||
detachFromAppComponent();
|
||||
@@ -633,16 +597,14 @@ import java.util.Set;
|
||||
broadcastReceiverAware.onAttachedToBroadcastReceiver(broadcastReceiverPluginBinding);
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachFromBroadcastReceiver() {
|
||||
if (isAttachedToBroadcastReceiver()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#detachFromBroadcastReceiver");
|
||||
Log.v(TAG, "Detaching from BroadcastReceiver: " + broadcastReceiver);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#detachFromBroadcastReceiver");
|
||||
try {
|
||||
// Notify all BroadcastReceiverAware plugins that they are no longer attached to a
|
||||
// BroadcastReceiver.
|
||||
@@ -651,7 +613,7 @@ import java.util.Set;
|
||||
broadcastReceiverAware.onDetachedFromBroadcastReceiver();
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
@@ -670,9 +632,8 @@ import java.util.Set;
|
||||
@Override
|
||||
public void attachToContentProvider(
|
||||
@NonNull ContentProvider contentProvider, @NonNull Lifecycle lifecycle) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#attachToContentProvider");
|
||||
Log.v(TAG, "Attaching to ContentProvider: " + contentProvider);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#attachToContentProvider");
|
||||
try {
|
||||
// If we were already attached to an Android component, detach from it.
|
||||
detachFromAppComponent();
|
||||
@@ -689,16 +650,14 @@ import java.util.Set;
|
||||
contentProviderAware.onAttachedToContentProvider(contentProviderPluginBinding);
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachFromContentProvider() {
|
||||
if (isAttachedToContentProvider()) {
|
||||
Trace.beginSection("FlutterEngineConnectionRegistry#detachFromContentProvider");
|
||||
Log.v(TAG, "Detaching from ContentProvider: " + contentProvider);
|
||||
|
||||
TraceSection.begin("FlutterEngineConnectionRegistry#detachFromContentProvider");
|
||||
try {
|
||||
// Notify all ContentProviderAware plugins that they are no longer attached to a
|
||||
// ContentProvider.
|
||||
@@ -706,7 +665,7 @@ import java.util.Set;
|
||||
contentProviderAware.onDetachedFromContentProvider();
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
} else {
|
||||
Log.e(
|
||||
|
||||
@@ -8,13 +8,13 @@ import android.content.res.AssetManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.tracing.Trace;
|
||||
import io.flutter.FlutterInjector;
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.engine.FlutterJNI;
|
||||
import io.flutter.embedding.engine.loader.FlutterLoader;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.plugin.common.StringCodec;
|
||||
import io.flutter.util.TraceSection;
|
||||
import io.flutter.view.FlutterCallbackInformation;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
@@ -141,10 +141,9 @@ public class DartExecutor implements BinaryMessenger {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.beginSection("DartExecutor#executeDartEntrypoint");
|
||||
Log.v(TAG, "Executing Dart entrypoint: " + dartEntrypoint);
|
||||
|
||||
TraceSection.begin("DartExecutor#executeDartEntrypoint");
|
||||
try {
|
||||
Log.v(TAG, "Executing Dart entrypoint: " + dartEntrypoint);
|
||||
flutterJNI.runBundleAndSnapshotFromLibrary(
|
||||
dartEntrypoint.pathToBundle,
|
||||
dartEntrypoint.dartEntrypointFunctionName,
|
||||
@@ -154,7 +153,7 @@ public class DartExecutor implements BinaryMessenger {
|
||||
|
||||
isApplicationRunning = true;
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,10 +170,9 @@ public class DartExecutor implements BinaryMessenger {
|
||||
return;
|
||||
}
|
||||
|
||||
Trace.beginSection("DartExecutor#executeDartCallback");
|
||||
Log.v(TAG, "Executing Dart callback: " + dartCallback);
|
||||
|
||||
TraceSection.begin("DartExecutor#executeDartCallback");
|
||||
try {
|
||||
Log.v(TAG, "Executing Dart callback: " + dartCallback);
|
||||
flutterJNI.runBundleAndSnapshotFromLibrary(
|
||||
dartCallback.pathToBundle,
|
||||
dartCallback.callbackHandle.callbackName,
|
||||
@@ -184,7 +182,7 @@ public class DartExecutor implements BinaryMessenger {
|
||||
|
||||
isApplicationRunning = true;
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ package io.flutter.embedding.engine.dart;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.tracing.Trace;
|
||||
import io.flutter.FlutterInjector;
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.engine.FlutterJNI;
|
||||
import io.flutter.plugin.common.BinaryMessenger;
|
||||
import io.flutter.util.TraceSection;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@@ -269,10 +269,9 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
|
||||
@NonNull String channel,
|
||||
@Nullable ByteBuffer message,
|
||||
@Nullable BinaryMessenger.BinaryReply callback) {
|
||||
Trace.beginSection("DartMessenger#send on " + channel);
|
||||
Log.v(TAG, "Sending message with callback over channel '" + channel + "'");
|
||||
|
||||
TraceSection.begin("DartMessenger#send on " + channel);
|
||||
try {
|
||||
Log.v(TAG, "Sending message with callback over channel '" + channel + "'");
|
||||
int replyId = nextReplyId++;
|
||||
if (callback != null) {
|
||||
pendingReplies.put(replyId, callback);
|
||||
@@ -283,7 +282,7 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
|
||||
flutterJNI.dispatchPlatformMessage(channel, message, message.position(), replyId);
|
||||
}
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +314,7 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
|
||||
final DartMessengerTaskQueue taskQueue = (handlerInfo != null) ? handlerInfo.taskQueue : null;
|
||||
Runnable myRunnable =
|
||||
() -> {
|
||||
Trace.beginSection("DartMessenger#handleMessageFromDart on " + channel);
|
||||
TraceSection.begin("DartMessenger#handleMessageFromDart on " + channel);
|
||||
try {
|
||||
invokeHandler(handlerInfo, message, replyId);
|
||||
if (message != null && message.isDirect()) {
|
||||
@@ -326,7 +325,7 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler {
|
||||
} finally {
|
||||
// This is deleting the data underneath the message object.
|
||||
flutterJNI.cleanupMessageData(messageData);
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
};
|
||||
final DartMessengerTaskQueue nonnullTaskQueue =
|
||||
|
||||
@@ -18,12 +18,12 @@ import android.os.SystemClock;
|
||||
import android.view.WindowManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.tracing.Trace;
|
||||
import io.flutter.BuildConfig;
|
||||
import io.flutter.FlutterInjector;
|
||||
import io.flutter.Log;
|
||||
import io.flutter.embedding.engine.FlutterJNI;
|
||||
import io.flutter.util.PathUtils;
|
||||
import io.flutter.util.TraceSection;
|
||||
import io.flutter.view.VsyncWaiter;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -149,8 +149,7 @@ public class FlutterLoader {
|
||||
throw new IllegalStateException("startInitialization must be called on the main thread");
|
||||
}
|
||||
|
||||
Trace.beginSection("FlutterLoader#startInitialization");
|
||||
|
||||
TraceSection.begin("FlutterLoader#startInitialization");
|
||||
try {
|
||||
// Ensure that the context is actually the application context.
|
||||
final Context appContext = applicationContext.getApplicationContext();
|
||||
@@ -179,8 +178,7 @@ public class FlutterLoader {
|
||||
new Callable<InitResult>() {
|
||||
@Override
|
||||
public InitResult call() {
|
||||
Trace.beginSection("FlutterLoader initTask");
|
||||
|
||||
TraceSection.begin("FlutterLoader initTask");
|
||||
try {
|
||||
ResourceExtractor resourceExtractor = initResources(appContext);
|
||||
|
||||
@@ -200,13 +198,13 @@ public class FlutterLoader {
|
||||
PathUtils.getCacheDirectory(appContext),
|
||||
PathUtils.getDataDirectory(appContext));
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
initResultFuture = executorService.submit(initTask);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +229,8 @@ public class FlutterLoader {
|
||||
throw new IllegalStateException(
|
||||
"ensureInitializationComplete must be called after startInitialization");
|
||||
}
|
||||
Trace.beginSection("FlutterLoader#ensureInitializationComplete");
|
||||
|
||||
TraceSection.begin("FlutterLoader#ensureInitializationComplete");
|
||||
try {
|
||||
InitResult result = initResultFuture.get();
|
||||
|
||||
@@ -332,7 +330,7 @@ public class FlutterLoader {
|
||||
Log.e(TAG, "Flutter initialization failed.", e);
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
Trace.endSection();
|
||||
TraceSection.end();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package io.flutter.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.tracing.Trace;
|
||||
|
||||
public final class TraceSection {
|
||||
/**
|
||||
* Wraps Trace.beginSection to ensure that the line length stays below 127 code units.
|
||||
*
|
||||
* @param sectionName The string to display as the section name in the trace.
|
||||
*/
|
||||
public static void begin(@NonNull String sectionName) {
|
||||
sectionName = sectionName.length() < 124 ? sectionName : sectionName.substring(0, 124) + "...";
|
||||
Trace.beginSection(sectionName);
|
||||
}
|
||||
|
||||
/** Wraps Trace.endSection. */
|
||||
public static void end() throws RuntimeException {
|
||||
Trace.endSection();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,23 @@ import sys
|
||||
ANDROID_LOG_CLASS = 'android.util.Log'
|
||||
FLUTTER_LOG_CLASS = 'io.flutter.Log'
|
||||
|
||||
ANDROIDX_TRACE_CLASS = 'androidx.tracing.Trace'
|
||||
ANDROID_TRACE_CLASS = 'android.tracing.Trace'
|
||||
FLUTTER_TRACE_CLASS = 'io.flutter.util.TraceSection'
|
||||
|
||||
|
||||
def CheckBadFiles(bad_files, bad_class, good_class):
|
||||
if bad_files:
|
||||
print('')
|
||||
print('Illegal import %s detected in the following files:' % bad_class)
|
||||
for bad_file in bad_files:
|
||||
print(' - ' + bad_file)
|
||||
print('Use %s instead.' % good_class)
|
||||
print('')
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Checks Flutter Android library for forbidden imports')
|
||||
parser.add_argument('--stamp', type=str, required=True)
|
||||
@@ -20,22 +37,24 @@ def main():
|
||||
|
||||
open(args.stamp, 'a').close()
|
||||
|
||||
bad_files = []
|
||||
bad_log_files = []
|
||||
bad_trace_files = []
|
||||
|
||||
for file in args.files:
|
||||
if file.endswith(os.path.join('io', 'flutter', 'Log.java')):
|
||||
if (file.endswith(os.path.join('io', 'flutter', 'Log.java')) or
|
||||
file.endswith(os.path.join('io', 'flutter', 'util', 'TraceSection.java'))):
|
||||
continue
|
||||
with open(file) as f:
|
||||
if ANDROID_LOG_CLASS in f.read():
|
||||
bad_files.append(file)
|
||||
contents = f.read()
|
||||
if ANDROID_LOG_CLASS in contents:
|
||||
bad_log_files.append(file)
|
||||
if ANDROIDX_TRACE_CLASS in contents or ANDROID_TRACE_CLASS in contents:
|
||||
bad_trace_files.append(file)
|
||||
|
||||
if bad_files:
|
||||
print('')
|
||||
print('Illegal import %s detected in the following files:' % ANDROID_LOG_CLASS)
|
||||
for bad_file in bad_files:
|
||||
print(' - ' + bad_file)
|
||||
print('Use %s instead.' % FLUTTER_LOG_CLASS)
|
||||
print('')
|
||||
has_bad_files = CheckBadFiles(bad_log_files, ANDROID_LOG_CLASS, FLUTTER_LOG_CLASS)
|
||||
has_bad_files = has_bad_files or CheckBadFiles(bad_trace_files, 'android[x].tracing.Trace', FLUTTER_TRACE_CLASS)
|
||||
|
||||
if has_bad_files:
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/util/ViewUtils.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/util/Predicate.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/util/PathUtils.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/util/TraceSection.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/KeyboardManager.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java" />
|
||||
<src file="../../../flutter/shell/platform/android/io/flutter/embedding/android/FlutterPlayStoreSplitApplication.java" />
|
||||
|
||||
Reference in New Issue
Block a user