From b959b9627080362e119a6e4425c9c2b0e4f313b9 Mon Sep 17 00:00:00 2001 From: "shiliu.wang@intel.com" Date: Mon, 21 Jul 2014 07:11:06 +0000 Subject: [PATCH] [Android] Implement ScreenOrientation.unlock align with spec This is for compliance with ScreenOrientation (https://w3c.github.io/screen-orientation). When unlock screen orientation, it should lock the orientation to default orientation. Previous implementation is to set the orientation to "unspecified", which is not fully aligned with spec. Instead, read the configuration from the activity metadata in AndroidManifest.xml and set the orientation accordingly. BUG=394214 Review URL: https://codereview.chromium.org/399553002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284396 0039d316-1c4b-4281-b951-d872f2087c98 (cherry picked from commit 11420f58b5bd1ea957624f482ec0c8b45245ab14) --- AUTHORS | 1 + .../content/browser/ScreenOrientationProvider.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 21f28d2f0c699..edca747be7e57 100644 --- a/AUTHORS +++ b/AUTHORS @@ -355,6 +355,7 @@ Sevan Janiyan ShankarGanesh K Shez Baig Shiliu Wang +Shiliu Wang Shouqun Liu Shreyas VA Simon Arlott diff --git a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java index 47e79e6a06f28..0aebd440be7f9 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java +++ b/content/public/android/java/src/org/chromium/content/browser/ScreenOrientationProvider.java @@ -6,6 +6,7 @@ import android.app.Activity; import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; import android.util.Log; import com.google.common.annotations.VisibleForTesting; @@ -74,7 +75,17 @@ void unlockOrientation() { return; } - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + int defaultOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + + try { + ActivityInfo info = activity.getPackageManager().getActivityInfo( + activity.getComponentName(), PackageManager.GET_META_DATA); + defaultOrientation = info.screenOrientation; + } catch (PackageManager.NameNotFoundException e) { + // Do nothing, defaultOrientation should be SCREEN_ORIENTATION_UNSPECIFIED. + } finally { + activity.setRequestedOrientation(defaultOrientation); + } } private ScreenOrientationProvider() {