Commit 57b42b8c authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android TWA] Delay screen orientation requests till transparency is removed

This CL:
- Delays screen orientation requests till transparency is removed on
SDK 26. Calling Activity#setRequestedOrientation() on a translucent
activity throws an exception on Android O but not Android O MR1
- Restricts the screen orientation delay for WebAPKs to just SDK 26

BUG=968196

Change-Id: Ie7d2725e0a35940e049eb888d11e3521c4bbec31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634417Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarPavel Shmakov <pshmakov@chromium.org>
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664768}
parent dd575a93
......@@ -11,6 +11,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.Build;
import android.os.Bundle;
import android.support.customtabs.TrustedWebUtils;
import android.support.customtabs.TrustedWebUtils.SplashScreenParamKey;
......@@ -27,6 +28,9 @@ import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.webapps.SplashController;
import org.chromium.chrome.browser.webapps.SplashDelegate;
import org.chromium.chrome.browser.webapps.SplashscreenObserver;
import org.chromium.content_public.browser.ScreenOrientationProvider;
import org.chromium.ui.base.ActivityWindowAndroid;
import javax.inject.Inject;
......@@ -56,20 +60,27 @@ import javax.inject.Inject;
* gc-ed when it finishes its job (to that end, it removes all observers it has set).
* If these lifecycle assumptions change, consider whether @ActivityScope needs to be added.
*/
public class TwaSplashController implements InflationObserver, SplashDelegate {
public class TwaSplashController
implements InflationObserver, SplashDelegate, SplashscreenObserver {
private final SplashController mSplashController;
private final Activity mActivity;
private final ActivityWindowAndroid mActivityWindowAndroid;
private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final ScreenOrientationProvider mScreenOrientationProvider;
private final SplashImageHolder mSplashImageCache;
private final CustomTabIntentDataProvider mIntentDataProvider;
@Inject
public TwaSplashController(SplashController splashController, Activity activity,
ActivityLifecycleDispatcher lifecycleDispatcher, SplashImageHolder splashImageCache,
ActivityWindowAndroid activityWindowAndroid,
ActivityLifecycleDispatcher lifecycleDispatcher,
ScreenOrientationProvider screenOrientationProvider, SplashImageHolder splashImageCache,
CustomTabIntentDataProvider intentDataProvider) {
mSplashController = splashController;
mActivity = activity;
mActivityWindowAndroid = activityWindowAndroid;
mLifecycleDispatcher = lifecycleDispatcher;
mScreenOrientationProvider = screenOrientationProvider;
mSplashImageCache = splashImageCache;
mIntentDataProvider = intentDataProvider;
......@@ -78,7 +89,14 @@ public class TwaSplashController implements InflationObserver, SplashDelegate {
mSplashController.setConfig(
this, true /* isWindowInitiallyTranslucent */, splashHideAnimationDurationMs);
mSplashController.addObserver(this);
lifecycleDispatcher.register(this);
// Setting the screen orientation while the activity is translucent throws an exception on
// O (but not on O MR1). Delay setting it.
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
mScreenOrientationProvider.delayOrientationRequests(mActivityWindowAndroid);
}
}
@Override
......@@ -114,6 +132,14 @@ public class TwaSplashController implements InflationObserver, SplashDelegate {
mSplashController.bringSplashBackToFront();
}
@Override
public void onTranslucencyRemoved() {
mScreenOrientationProvider.runDelayedOrientationRequests(mActivityWindowAndroid);
}
@Override
public void onSplashscreenHidden(long startTimestamp, long endTimestamp) {}
private void applyCustomizationsToSplashScreenView(ImageView imageView) {
Bundle params = getSplashScreenParamsFromIntent();
......
......@@ -23,6 +23,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.ToolbarManager;
import org.chromium.chrome.browser.ui.system.StatusBarColorController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.content_public.browser.ScreenOrientationProvider;
import org.chromium.ui.base.ActivityWindowAndroid;
import javax.inject.Named;
......@@ -137,4 +138,9 @@ public class ChromeActivityCommonsModule {
public StatusBarColorController provideStatusBarColorController() {
return mActivity.getStatusBarColorController();
}
@Provides
public ScreenOrientationProvider provideScreenOrientationProvider() {
return ScreenOrientationProvider.getInstance();
}
}
......@@ -865,10 +865,11 @@ public class WebappActivity extends SingleTabActivity {
/** Sets the screen orientation. */
private void applyScreenOrientation() {
if (mWebappInfo.isSplashProvidedByWebApk()) {
if (mWebappInfo.isSplashProvidedByWebApk()
&& Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
// When the splash screen is provided by the WebAPK, the activity is initially
// translucent. Setting the screen orientation while the activity is translucent
// throws an exception. Delay setting it.
// throws an exception on O (but not O MR1). Delay setting it.
ScreenOrientationProvider.getInstance().delayOrientationRequests(getWindowAndroid());
addSplashscreenObserver(new SplashscreenObserver() {
......
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