Add initial tracing to ComponentActivity.reportFullyDrawn
Test: Tests in 'androidx.activity'
Test: AppStartupHelperTest (with manual change to Component activity + manual tracing)
Relnote: "Add tracing to ComponentActivity.reportFullyDrawn"
Bug: 172604392
Once S is API stable, we can also set a max API for this tracing
behavior.
Change-Id: Ic7632bef49a1440843cba550b1da27736d5abe41
(cherry picked from commit 0cc052fb687e418de019f1b0ff3a51c609c9094f)
diff --git a/activity/activity/build.gradle b/activity/activity/build.gradle
index e683bb6..1159550 100644
--- a/activity/activity/build.gradle
+++ b/activity/activity/build.gradle
@@ -27,6 +27,7 @@
api(projectOrArtifact(":lifecycle:lifecycle-viewmodel"))
api(projectOrArtifact(":savedstate:savedstate"))
api(projectOrArtifact(":lifecycle:lifecycle-viewmodel-savedstate"))
+ implementation("androidx.tracing:tracing:1.0.0")
androidTestImplementation(projectOrArtifact(":lifecycle:lifecycle-runtime-testing"))
androidTestImplementation(KOTLIN_STDLIB)
diff --git a/activity/activity/src/main/java/androidx/activity/ComponentActivity.java b/activity/activity/src/main/java/androidx/activity/ComponentActivity.java
index 3ea130a..3368985 100644
--- a/activity/activity/src/main/java/androidx/activity/ComponentActivity.java
+++ b/activity/activity/src/main/java/androidx/activity/ComponentActivity.java
@@ -80,6 +80,7 @@
import androidx.savedstate.SavedStateRegistryController;
import androidx.savedstate.SavedStateRegistryOwner;
import androidx.savedstate.ViewTreeSavedStateRegistryOwner;
+import androidx.tracing.Trace;
import java.util.ArrayList;
import java.util.List;
@@ -690,16 +691,24 @@
@Override
public void reportFullyDrawn() {
- if (Build.VERSION.SDK_INT > 19) {
- super.reportFullyDrawn();
- } else if (Build.VERSION.SDK_INT == 19 && ContextCompat.checkSelfPermission(this,
- Manifest.permission.UPDATE_DEVICE_STATS) == PackageManager.PERMISSION_GRANTED) {
- // On API 19, the Activity.reportFullyDrawn() method requires the UPDATE_DEVICE_STATS
- // permission, otherwise it throws an exception. Instead of throwing, we fall back to
- // a no-op call.
- super.reportFullyDrawn();
+ try {
+ if (Trace.isEnabled()) {
+ Trace.beginSection("reportFullyDrawn() for " + getComponentName());
+ }
+
+ if (Build.VERSION.SDK_INT > 19) {
+ super.reportFullyDrawn();
+ } else if (Build.VERSION.SDK_INT == 19 && ContextCompat.checkSelfPermission(this,
+ Manifest.permission.UPDATE_DEVICE_STATS) == PackageManager.PERMISSION_GRANTED) {
+ // On API 19, the Activity.reportFullyDrawn() method requires the
+ // UPDATE_DEVICE_STATS permission, otherwise it throws an exception. Instead of
+ // throwing, we fall back to a no-op call.
+ super.reportFullyDrawn();
+ }
+ // The Activity.reportFullyDrawn() got added in API 19, fall back to a no-op call if
+ // this method gets called on devices with an earlier version.
+ } finally {
+ Trace.endSection();
}
- // The Activity.reportFullyDrawn() got added in API 19, fall back to a no-op call if this
- // method gets called on devices with an earlier version.
}
}