Commit 7ea248a7 authored by Sicheng Li's avatar Sicheng Li Committed by Commit Bot

Fix orientation for launching WebAPKs splash screen

In this CL, we fixed the screenOrientation when launching with a
landscape splash screen, it started with a portrait mode. We fixed this
by setting the android:screenOrientation="screenOrientationLockType",
reading from the Web manifest file, for the individual activities.


Bug: 1032570
Change-Id: I1ae59a5171a5a032aa79fdc5123239074e2a58f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248321
Commit-Queue: Sicheng Li <scli@google.com>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Reviewed-by: default avatarGlenn Hartmann <hartmanng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781049}
parent 8abb7d5d
......@@ -54,6 +54,7 @@
<activity android:name="org.chromium.webapk.shell_apk.h2o.H2OOpaqueMainActivity"
android:theme="@style/SplashTheme"
android:relinquishTaskIdentity="true"
android:screenOrientation="{{{android_orientation}}}"
android:enabled="[[#use_new_splash]]@bool/opaque_main_activity_enabled_default[[/use_new_splash]][[^use_new_splash]]false[[/use_new_splash]]">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......@@ -63,6 +64,7 @@
</activity>
<activity android:name="org.chromium.webapk.shell_apk.h2o.SplashActivity"
android:theme="@style/SplashTheme"
android:screenOrientation="{{{android_orientation}}}"
android:launchMode="singleTask">
</activity>
<provider android:name="org.chromium.webapk.shell_apk.h2o.SplashContentProvider"
......
......@@ -12,4 +12,4 @@
# //chrome/android/webapk/shell_apk:webapk is changed. This includes
# Java files, Android resource files and AndroidManifest.xml. Does not affect
# Chrome.apk
current_shell_apk_version = 128
current_shell_apk_version = 129
......@@ -9,6 +9,7 @@
"start_url": "https://pwa-directory.appspot.com/",
"display_mode": "standalone",
"orientation": "portrait",
"android_orientation": "unspecified",
"theme_color": "2147483648L",
"background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
......
......@@ -9,6 +9,7 @@
"start_url": "https://www.google.com/maps/@37.7890183,-122.3915063,15z?force=pwa",
"display_mode": "standalone",
"orientation": "portrait",
"android_orientation": "unspecified",
"theme_color": "2147483648L",
"background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
......
......@@ -10,6 +10,7 @@
"logged_intent_url_param": "originalUrl",
"display_mode": "standalone",
"orientation": "portrait",
"android_orientation": "unspecified",
"theme_color": "2147483648L",
"background_color": "2147483648L",
"background_color_xml": "#F8F9FA",
......
......@@ -274,43 +274,27 @@ public class WebApkUtils {
}
/** Computes the screen lock orientation from the passed-in metadata and the display size. */
public static int computeScreenLockOrientationFromMetaData(Context context, Bundle metadata) {
public static int computeNaturalScreenLockOrientationFromMetaData(
Context context, Bundle metadata) {
String orientation = metadata.getString(WebApkMetaDataKeys.ORIENTATION);
if (orientation == null) {
if (orientation == null || !orientation.equals("natural")) {
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
} else if (orientation.equals("portrait-primary")) {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} else if (orientation.equals("portrait-secondary")) {
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
} else if (orientation.equals("landscape-primary")) {
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else if (orientation.equals("landscape-secondary")) {
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
} else if (orientation.equals("portrait")) {
return ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
} else if (orientation.equals("landscape")) {
return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
} else if (orientation.equals("any")) {
return ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
} else if (orientation.equals("natural")) {
WindowManager windowManager =
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
if (display.getHeight() >= display.getWidth()) {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
} else {
if (display.getHeight() < display.getWidth()) {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
WindowManager windowManager =
(WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) {
if (display.getHeight() >= display.getWidth()) {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
} else {
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
if (display.getHeight() < display.getWidth()) {
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
/** Grants the host browser permission to the shared files if any. */
......
......@@ -154,7 +154,8 @@ public class SplashActivity extends Activity {
Bundle metadata = WebApkUtils.readMetaData(this);
updateStatusBar(metadata);
int orientation = WebApkUtils.computeScreenLockOrientationFromMetaData(this, metadata);
int orientation =
WebApkUtils.computeNaturalScreenLockOrientationFromMetaData(this, metadata);
if (orientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
setRequestedOrientation(orientation);
}
......
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