3636import androidx .browser .trusted .TrustedWebActivityIntentBuilder ;
3737import androidx .core .content .ContextCompat ;
3838
39+ import com .google .androidbrowserhelper .BuildConfig ;
3940import com .google .androidbrowserhelper .trusted .ChromeOsSupport ;
4041import com .google .androidbrowserhelper .trusted .splashscreens .SplashScreenStrategy ;
4142
@@ -48,6 +49,12 @@ public class TwaLauncher {
4849
4950 private static final int DEFAULT_SESSION_ID = 96375 ;
5051
52+ private static final String EXTRA_STARTUP_UPTIME_MILLIS =
53+ "org.chromium.chrome.browser.customtabs.trusted.STARTUP_UPTIME_MILLIS" ;
54+
55+ private static final String EXTRA_ANDROID_BROWSER_HELPER_VERSION =
56+ "org.chromium.chrome.browser.ANDROID_BROWSER_HELPER_VERSION" ;
57+
5158 public static final FallbackStrategy CCT_FALLBACK_STRATEGY =
5259 (context , twaBuilder , providerPackage , completionCallback ) -> {
5360 // CustomTabsIntent will fall back to launching the Browser if there are no Custom Tabs
@@ -96,6 +103,8 @@ public class TwaLauncher {
96103
97104 private boolean mDestroyed ;
98105
106+ private long mStartupUptimeMillis ;
107+
99108 public interface FallbackStrategy {
100109 void launch (Context context ,
101110 TrustedWebActivityIntentBuilder twaBuilder ,
@@ -269,6 +278,11 @@ private void launchWhenSplashScreenReady(TrustedWebActivityIntentBuilder builder
269278 }
270279 Log .d (TAG , "Launching Trusted Web Activity." );
271280 TrustedWebActivityIntent intent = builder .build (mSession );
281+ if (mStartupUptimeMillis != 0 ) {
282+ intent .getIntent ().putExtra (EXTRA_STARTUP_UPTIME_MILLIS , mStartupUptimeMillis );
283+ }
284+ intent .getIntent ().putExtra (
285+ EXTRA_ANDROID_BROWSER_HELPER_VERSION , BuildConfig .LIBRARY_VERSION );
272286 FocusActivity .addToIntent (intent .getIntent (), mContext );
273287 intent .launchTrustedWebActivity (mContext );
274288
@@ -299,6 +313,15 @@ public String getProviderPackage() {
299313 return mProviderPackage ;
300314 }
301315
316+ /**
317+ * Sets the timestamp (in SystemClock.uptimeMillis()) when the TWA launcher
318+ * activity was created. This timestamp is used to report the full startup
319+ * duration to the browser.
320+ */
321+ public void setStartupUptimeMillis (long startupUptimeMillis ) {
322+ mStartupUptimeMillis = startupUptimeMillis ;
323+ }
324+
302325 private class TwaCustomTabsServiceConnection extends CustomTabsServiceConnection {
303326 private Runnable mOnSessionCreatedRunnable ;
304327 private Runnable mOnSessionCreationFailedRunnable ;
0 commit comments