Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,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
Expand Down
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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;
Expand All @@ -33,6 +32,7 @@
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I'm confused. Where is this defined? Is this PR missing a commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whups! There were two missing files in what I pushed up, fixing that now.

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -123,8 +123,7 @@ public void destroy() {

@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(
Expand Down Expand Up @@ -192,7 +191,7 @@ public void add(@NonNull FlutterPlugin plugin) {
}
}
} finally {
Trace.endSection();
TraceSection.end();
}
}

Expand Down Expand Up @@ -220,10 +219,8 @@ public void remove(@NonNull Class<? extends FlutterPlugin> pluginClass) {
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.
Expand Down Expand Up @@ -273,7 +270,7 @@ public void remove(@NonNull Class<? extends FlutterPlugin> pluginClass) {
plugin.onDetachedFromEngine(pluginBinding);
plugins.remove(pluginClass);
} finally {
Trace.endSection();
TraceSection.end();
}
}

Expand Down Expand Up @@ -316,16 +313,8 @@ private Activity attachedActivity() {
@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();
}
Expand All @@ -334,7 +323,7 @@ public void attachToActivity(
this.exclusiveActivity = exclusiveActivity;
attachToActivityInternal(exclusiveActivity.getAppComponent(), lifecycle);
} finally {
Trace.endSection();
TraceSection.end();
}
}

Expand Down Expand Up @@ -362,9 +351,7 @@ private void attachToActivityInternal(@NonNull Activity activity, @NonNull Lifec
@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;

Expand All @@ -374,7 +361,7 @@ public void detachFromActivityForConfigChanges() {

detachFromActivityInternal();
} finally {
Trace.endSection();
TraceSection.end();
}
} else {
Log.e(TAG, "Attempted to detach plugins from an Activity when no Activity was attached.");
Expand All @@ -384,17 +371,15 @@ public void detachFromActivityForConfigChanges() {
@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.");
Expand All @@ -412,15 +397,13 @@ private void detachFromActivityInternal() {
@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(
Expand All @@ -433,14 +416,12 @@ public boolean onRequestPermissionsResult(

@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(
Expand All @@ -453,14 +434,12 @@ public boolean onActivityResult(int requestCode, int resultCode, @Nullable Inten

@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(
Expand All @@ -472,14 +451,12 @@ public void onNewIntent(@NonNull Intent intent) {

@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(
Expand All @@ -491,14 +468,12 @@ public void onUserLeaveHint() {

@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(
Expand All @@ -510,14 +485,12 @@ public void onSaveInstanceState(@NonNull Bundle bundle) {

@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(
Expand All @@ -536,9 +509,7 @@ private boolean isAttachedToService() {
@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();
Expand All @@ -551,16 +522,14 @@ public void attachToService(
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()) {
Expand All @@ -570,7 +539,7 @@ public void detachFromService() {
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.");
Expand All @@ -580,27 +549,24 @@ public void detachFromService() {
@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();
}
}
}

@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();
}
}
}
Expand All @@ -614,9 +580,7 @@ private boolean isAttachedToBroadcastReceiver() {
@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();
Expand All @@ -633,16 +597,14 @@ public void attachToBroadcastReceiver(
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.
Expand All @@ -651,7 +613,7 @@ public void detachFromBroadcastReceiver() {
broadcastReceiverAware.onDetachedFromBroadcastReceiver();
}
} finally {
Trace.endSection();
TraceSection.end();
}
} else {
Log.e(
Expand All @@ -670,9 +632,8 @@ private boolean isAttachedToContentProvider() {
@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();
Expand All @@ -689,24 +650,22 @@ public void attachToContentProvider(
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.
for (ContentProviderAware contentProviderAware : contentProviderAwarePlugins.values()) {
contentProviderAware.onDetachedFromContentProvider();
}
} finally {
Trace.endSection();
TraceSection.end();
}
} else {
Log.e(
Expand Down
Loading