Commit d943b2e6 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

move WebApk bringSplashBackToFront to onPostInflationStartup

To make TWA and WebAPK the same.
As far as I can tell, there is no visual difference.

Since both TWA and WebApk can do it in the shared SplashController,
TwaSplashController doesn't need the lifecycleDispatcher anymore.

Bug: 1129093
Change-Id: I320ece59b28d2c5b39da0869f97f5ac2baf5f9cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414845Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821360}
parent 82138d8f
......@@ -189,6 +189,7 @@ public class SplashController
// In rare cases I see toolbar flickering. TODO(pshmakov): investigate why.
mActivity.findViewById(R.id.coordinator).setVisibility(View.INVISIBLE);
}
bringSplashBackToFront();
}
@Override
......
......@@ -27,8 +27,6 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.browserservices.ui.splashscreen.SplashController;
import org.chromium.chrome.browser.browserservices.ui.splashscreen.SplashDelegate;
import org.chromium.chrome.browser.customtabs.TranslucentCustomTabActivity;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.InflationObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.util.ColorUtils;
......@@ -58,30 +56,25 @@ import javax.inject.Inject;
* occurs.
*
* Lifecycle: this class is resolved only once when CustomTabActivity is launched, and is
* gc-ed when it finishes its job (to that end, it removes all observers it has set).
* gc-ed when it finishes its job.
* If these lifecycle assumptions change, consider whether @ActivityScope needs to be added.
*/
public class TwaSplashController implements InflationObserver, SplashDelegate {
public class TwaSplashController implements SplashDelegate {
// TODO(pshmakov): move this to AndroidX.
private static final String KEY_SHOWN_IN_CLIENT =
"androidx.browser.trusted.KEY_SPLASH_SCREEN_SHOWN_IN_CLIENT";
private final SplashController mSplashController;
private final Activity mActivity;
private final ActivityWindowAndroid mActivityWindowAndroid;
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final SplashImageHolder mSplashImageCache;
private final BrowserServicesIntentDataProvider mIntentDataProvider;
@Inject
public TwaSplashController(SplashController splashController, Activity activity,
ActivityWindowAndroid activityWindowAndroid,
ActivityLifecycleDispatcher lifecycleDispatcher, SplashImageHolder splashImageCache,
ActivityWindowAndroid activityWindowAndroid, SplashImageHolder splashImageCache,
BrowserServicesIntentDataProvider intentDataProvider) {
mSplashController = splashController;
mActivity = activity;
mActivityWindowAndroid = activityWindowAndroid;
mLifecycleDispatcher = lifecycleDispatcher;
mSplashImageCache = splashImageCache;
mIntentDataProvider = intentDataProvider;
......@@ -89,15 +82,12 @@ public class TwaSplashController implements InflationObserver, SplashDelegate {
IntentUtils.safeGetInt(getSplashScreenParamsFromIntent(),
SplashScreenParamKey.KEY_FADE_OUT_DURATION_MS, 0);
mSplashController.setConfig(this, splashHideAnimationDurationMs);
lifecycleDispatcher.register(this);
}
@Override
public View buildSplashView() {
Bitmap bitmap = mSplashImageCache.takeImage(mIntentDataProvider.getSession());
if (bitmap == null) {
mLifecycleDispatcher.unregister(this);
return null;
}
ImageView splashView = new ImageView(mActivity);
......@@ -108,23 +98,13 @@ public class TwaSplashController implements InflationObserver, SplashDelegate {
}
@Override
public void onSplashHidden(Tab tab, long startTimestamp, long endTimestamp) {
mLifecycleDispatcher.unregister(this); // Unregister to get gc-ed
}
public void onSplashHidden(Tab tab, long startTimestamp, long endTimestamp) {}
@Override
public boolean shouldWaitForSubsequentPageLoadToHideSplash() {
return false;
}
@Override
public void onPreInflationStartup() {}
@Override
public void onPostInflationStartup() {
mSplashController.bringSplashBackToFront();
}
private void applyCustomizationsToSplashScreenView(ImageView imageView) {
Bundle params = getSplashScreenParamsFromIntent();
......
......@@ -61,14 +61,6 @@ public class WebappSplashController implements SplashDelegate {
}
}
/**
* Called once the Activity's main layout is inflated and added to the content view.
*/
public void onInitialLayoutInflationComplete() {
// TODO: TWAs do this in onPostInflationStart(). Determine if there is a visual difference.
mSplashController.bringSplashBackToFront();
}
@Override
public View buildSplashView() {
Context appContext = ContextUtils.getApplicationContext();
......
......@@ -11,10 +11,8 @@ import static org.chromium.chrome.browser.customtabs.content.CustomTabActivityNa
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
......@@ -24,11 +22,9 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.OneshotSupplier;
import org.chromium.base.supplier.OneshotSupplierImpl;
import org.chromium.base.task.PostTask;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.KeyboardShortcuts;
import org.chromium.chrome.browser.WarmupManager;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProvider;
import org.chromium.chrome.browser.browserservices.ui.controller.Verifier;
......@@ -61,7 +57,6 @@ import org.chromium.chrome.browser.webapps.SameTaskWebApkActivity;
import org.chromium.chrome.browser.webapps.WebappActivityCoordinator;
import org.chromium.chrome.browser.webapps.WebappExtras;
import org.chromium.components.embedder_support.delegate.WebContentsDelegateAndroid;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
* Contains functionality which is shared between {@link WebappActivity} and
......@@ -273,66 +268,6 @@ public abstract class BaseCustomTabActivity extends ChromeActivity<BaseCustomTab
return Runtime.getRuntime().availableProcessors();
}
@Override
protected void doLayoutInflation() {
// Conditionally do layout inflation synchronously if device has low core count.
// When layout inflation is done asynchronously, it blocks UI thread startup. While
// blocked, the UI thread will draw unnecessary frames - causing the lower priority
// layout inflation thread to be de-scheduled significantly more often, especially on
// devices with low core count. Thus for low core count devices, there is a startup
// performance improvement incurred by doing layout inflation synchronously.
// TODO: Determine whether this webapp speed optimization is still helpful given
// the current CCT speed optimizations.
if (!mIntentDataProvider.isWebappOrWebApkActivity() || getCoreCount() <= 2) {
super.doLayoutInflation();
return;
}
// Because we delay the layout inflation, the CompositorSurfaceManager and its
// SurfaceView(s) are created and attached late (ie after the first draw). At the time of
// the first attach of a SurfaceView to the view hierarchy (regardless of the SurfaceView's
// actual opacity), the window transparency hint changes (because the window creates a
// transparent hole and attaches the SurfaceView to that hole). This may cause older android
// versions to destroy the window and redraw it causing a flicker. This line sets the window
// transparency hint early so that when the SurfaceView gets attached later, the
// transparency hint need not change and no flickering occurs.
getWindow().setFormat(PixelFormat.TRANSLUCENT);
// No need to inflate layout synchronously since splash screen is displayed.
Runnable inflateTask = () -> {
ViewGroup mainView = WarmupManager.inflateViewHierarchy(BaseCustomTabActivity.this,
getControlContainerLayoutId(), getToolbarLayoutId());
if (isActivityFinishingOrDestroyed()) return;
if (mainView != null) {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (isActivityFinishingOrDestroyed()) return;
onLayoutInflated(mainView);
});
} else {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (isActivityFinishingOrDestroyed()) return;
BaseCustomTabActivity.super.doLayoutInflation();
});
}
};
// Run inflation task on UI thread due to threading issues in M85. See crbug.com/1112352
inflateTask.run();
}
private void onLayoutInflated(ViewGroup mainView) {
ViewGroup contentView = (ViewGroup) findViewById(android.R.id.content);
WarmupManager.transferViewHeirarchy(mainView, contentView);
onInitialLayoutInflationComplete();
}
@Override
protected void onInitialLayoutInflationComplete() {
if (mWebappActivityCoordinator != null) {
mWebappActivityCoordinator.onInitialLayoutInflationComplete();
}
super.onInitialLayoutInflationComplete();
}
@Override
public void initializeState() {
super.initializeState();
......
......@@ -33,7 +33,6 @@ public class WebappActivityCoordinator
private final BrowserServicesIntentDataProvider mIntentDataProvider;
private final WebappInfo mWebappInfo;
private final ChromeActivity<?> mActivity;
private final WebappSplashController mSplashController;
private final WebappDeferredStartupWithStorageHandler mDeferredStartupWithStorageHandler;
// Whether the current page is within the webapp's scope.
......@@ -47,13 +46,12 @@ public class WebappActivityCoordinator
WebappDeferredStartupWithStorageHandler deferredStartupWithStorageHandler,
WebappActionsNotificationManager actionsNotificationManager,
ActivityLifecycleDispatcher lifecycleDispatcher) {
// We don't need to do anything with |sharedActivityCoordinator| or
// We don't need to do anything with |sharedActivityCoordinator|, |splashController| or
// |actionsNotificationManager|. We just need to resolve it so that it starts working.
mIntentDataProvider = intentDataProvider;
mWebappInfo = WebappInfo.create(mIntentDataProvider);
mActivity = activity;
mSplashController = splashController;
mDeferredStartupWithStorageHandler = deferredStartupWithStorageHandler;
// WebappActiveTabUmaTracker sets itself as an observer of |activityTabProvider|.
......@@ -85,13 +83,6 @@ public class WebappActivityCoordinator
mDeferredStartupWithStorageHandler.initDeferredStartupForActivity();
}
/**
* Called once the Activity's main layout is inflated and added to the content view.
*/
public void onInitialLayoutInflationComplete() {
mSplashController.onInitialLayoutInflationComplete();
}
@Override
public void onPreInflationStartup() {
LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(mWebappInfo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment