diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-01-18 17:52:49 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-01-18 17:52:49 +0000 |
commit | f70360f37952e85e1aafa2409e0f210f38909531 (patch) | |
tree | 9d6b36921f47354ee76a1e0f47812c0323db971c | |
parent | 7cafe1d2b819581f412e4765b0dd4334f7d59c20 (diff) | |
parent | 8649a932a891f4081031029c4c4f803183484b47 (diff) | |
download | cts-pie-dev.tar.gz |
Merge "Helper: Added screen rotation support check" into pie-devpie-dev
-rw-r--r-- | tests/autofillservice/src/android/autofillservice/cts/Helper.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/autofillservice/src/android/autofillservice/cts/Helper.java b/tests/autofillservice/src/android/autofillservice/cts/Helper.java index 79347304610..14dbbdfb22b 100644 --- a/tests/autofillservice/src/android/autofillservice/cts/Helper.java +++ b/tests/autofillservice/src/android/autofillservice/cts/Helper.java @@ -38,6 +38,7 @@ import android.autofillservice.cts.common.SettingsHelper; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.graphics.Bitmap; import android.icu.util.Calendar; import android.os.Bundle; @@ -107,6 +108,9 @@ final class Helper { private static final String LOCAL_DIRECTORY = Environment.getExternalStorageDirectory() + "/CtsAutoFillServiceTestCases"; + private static final String RESOURCE_BOOLEAN_CONFIG_FORCE_DEFAULT_ORIENTATION = + "config_forceDefaultOrientation"; + /** * Helper interface used to filter nodes. * @@ -754,7 +758,35 @@ final class Helper { * Checks if screen orientation can be changed. */ public static boolean isRotationSupported(Context context) { - return !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK); + if (!isScreenRotationSupported(context)) { + Log.v(TAG, "isRotationSupported(): screen rotation not supported"); + return false; + } + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { + Log.v(TAG, "isRotationSupported(): has leanback feature"); + return false; + } + return true; + } + + /** + * Returns {@code true} if display rotation is supported, {@code false} otherwise. + */ + private static boolean isScreenRotationSupported(Context context) { + try { + return !getBoolean(context, RESOURCE_BOOLEAN_CONFIG_FORCE_DEFAULT_ORIENTATION); + } catch (Resources.NotFoundException e) { + Log.d(TAG, "Resource not found: " + + RESOURCE_BOOLEAN_CONFIG_FORCE_DEFAULT_ORIENTATION + + ". Assume rotation supported"); + return true; + } + } + + private static boolean getBoolean(Context context, String id) { + final Resources resources = context.getResources(); + final int booleanId = resources.getIdentifier(id, "bool", "android"); + return resources.getBoolean(booleanId); } /** |