From 18a2a55ece46f7a43b7593062a0e606185c9324e Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Thu, 3 Sep 2026 14:52:46 -0400 Subject: [PATCH 1/2] Add performance module and 1 code snippet --- performance/build.gradle.kts | 48 +++++++++++ performance/src/main/AndroidManifest.xml | 21 +++++ .../example/performance/vitals/LaunchTime.kt | 82 +++++++++++++++++++ settings.gradle.kts | 3 +- 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 performance/build.gradle.kts create mode 100644 performance/src/main/AndroidManifest.xml create mode 100644 performance/src/main/java/com/example/performance/vitals/LaunchTime.kt diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts new file mode 100644 index 000000000..f5ae78264 --- /dev/null +++ b/performance/build.gradle.kts @@ -0,0 +1,48 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.compose.compiler) +} + +kotlin { + jvmToolchain(17) +} + +android { + namespace = "com.example.performance" + compileSdk = libs.versions.compileSdk.get().toInt() + + defaultConfig { + applicationId = "com.example.performance" + minSdk = libs.versions.minSdk.get().toInt() + targetSdk = libs.versions.targetSdk.get().toInt() + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + buildFeatures { + compose = true + } +} + +dependencies { + val composeBom = platform(libs.androidx.compose.bom) + implementation(composeBom) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.runtime) + + testImplementation(libs.junit) + testImplementation(kotlin("test")) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.junit) + androidTestImplementation(libs.androidx.test.core) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.androidx.test.espresso.core) +} \ No newline at end of file diff --git a/performance/src/main/AndroidManifest.xml b/performance/src/main/AndroidManifest.xml new file mode 100644 index 000000000..3e3eaa782 --- /dev/null +++ b/performance/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt b/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt new file mode 100644 index 000000000..0866a2988 --- /dev/null +++ b/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt @@ -0,0 +1,82 @@ +/* + * Copyright 2026 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.performance.vitals + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch + +private object LaunchTimeSnippet { + // [START android_performance_launch_time_fully_drawn_reporter] + class MainActivity : ComponentActivity() { + + sealed interface ActivityState { + data object LOADING : ActivityState + data object LOADED : ActivityState + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + var activityState by remember { + mutableStateOf(ActivityState.LOADING as ActivityState) + } + fullyDrawnReporter.addOnReportDrawnListener { + activityState = ActivityState.LOADED + } + ReportFullyDrawnTheme { + when(activityState) { + is ActivityState.LOADING -> { + // Display the loading UI. + } + is ActivityState.LOADED -> { + // Display the full UI. + } + } + } + SideEffect { + fullyDrawnReporter.addReporter() + lifecycleScope.launch(Dispatchers.IO) { + // Perform the background operation. + fullyDrawnReporter.removeReporter() + } + fullyDrawnReporter.addReporter() + lifecycleScope.launch(Dispatchers.IO) { + // Perform the background operation. + fullyDrawnReporter.removeReporter() + } + } + } + } + } + // [END android_performance_launch_time_fully_drawn_reporter] +} + +@Composable +private fun ReportFullyDrawnTheme(content: @Composable () -> Unit) { + content() +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 31638d155..9c3d0ef53 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -60,5 +60,6 @@ include( ":cars", ":installprompt", ":telecom", - ":room" + ":room", + ":performance" ) \ No newline at end of file From 2861d1aafcdeebbc3cf16b1d5100f5d297db3292 Mon Sep 17 00:00:00 2001 From: Peng Quah Date: Fri, 4 Sep 2026 09:20:52 -0400 Subject: [PATCH 2/2] Update package name and cleanup dependencies - Rename namespace to com.example.android.performance - Declare MainActivity as launcher activity in manifest - Remove unused Compose UI and test dependencies - Add explicit lifecycle-runtime-compose and coroutines dependencies - Move MainActivity to top-level in LaunchTime.kt --- performance/build.gradle.kts | 18 ++++-------------- performance/src/main/AndroidManifest.xml | 13 +++++++++++-- .../example/performance/vitals/LaunchTime.kt | 4 +--- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/performance/build.gradle.kts b/performance/build.gradle.kts index f5ae78264..7c779ce36 100644 --- a/performance/build.gradle.kts +++ b/performance/build.gradle.kts @@ -8,11 +8,11 @@ kotlin { } android { - namespace = "com.example.performance" + namespace = "com.example.android.performance" compileSdk = libs.versions.compileSdk.get().toInt() defaultConfig { - applicationId = "com.example.performance" + applicationId = "com.example.android.performance" minSdk = libs.versions.minSdk.get().toInt() targetSdk = libs.versions.targetSdk.get().toInt() versionCode = 1 @@ -31,18 +31,8 @@ android { } dependencies { - val composeBom = platform(libs.androidx.compose.bom) - implementation(composeBom) - implementation(libs.androidx.core.ktx) implementation(libs.androidx.activity.compose) - implementation(libs.androidx.compose.ui) implementation(libs.androidx.compose.runtime) - - testImplementation(libs.junit) - testImplementation(kotlin("test")) - androidTestImplementation(libs.androidx.test.ext.junit) - androidTestImplementation(libs.junit) - androidTestImplementation(libs.androidx.test.core) - androidTestImplementation(libs.androidx.test.runner) - androidTestImplementation(libs.androidx.test.espresso.core) + implementation(libs.androidx.lifecycle.runtime.compose) + implementation(libs.kotlinx.coroutines.android) } \ No newline at end of file diff --git a/performance/src/main/AndroidManifest.xml b/performance/src/main/AndroidManifest.xml index 3e3eaa782..c9a15e479 100644 --- a/performance/src/main/AndroidManifest.xml +++ b/performance/src/main/AndroidManifest.xml @@ -16,6 +16,15 @@ --> - + + + + + + + + - \ No newline at end of file + diff --git a/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt b/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt index 0866a2988..174cc91fc 100644 --- a/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt +++ b/performance/src/main/java/com/example/performance/vitals/LaunchTime.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.example.performance.vitals +package com.example.android.performance.vitals import android.os.Bundle import androidx.activity.ComponentActivity @@ -29,7 +29,6 @@ import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -private object LaunchTimeSnippet { // [START android_performance_launch_time_fully_drawn_reporter] class MainActivity : ComponentActivity() { @@ -74,7 +73,6 @@ private object LaunchTimeSnippet { } } // [END android_performance_launch_time_fully_drawn_reporter] -} @Composable private fun ReportFullyDrawnTheme(content: @Composable () -> Unit) {