Add resolution check for Sharesheet CTS tests

OEMs are using small resolutions that break the current tests.
Check the DUT's height to confirm tests should pass with AOSP
Sharesheet UI.

Fixes: 162339761
Test: manual with various 'adb shell wm size'
Change-Id: Ibb29b261a2bfb64cc016a3c0b86db834fbc3160d
diff --git a/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java b/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
index f5ddc7c..ba22270 100644
--- a/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
+++ b/tests/tests/sharesheet/src/android/sharesheet/cts/CtsSharesheetDeviceTest.java
@@ -35,6 +35,7 @@
 import android.content.pm.ResolveInfo;
 import android.content.pm.ShortcutInfo;
 import android.content.pm.ShortcutManager;
+import android.graphics.Point;
 import android.graphics.drawable.Icon;
 import android.os.Bundle;
 import android.service.chooser.ChooserTarget;
@@ -101,6 +102,8 @@
 
     private Set<ComponentName> mTargetsToExclude;
 
+    private boolean mMeetsResolutionRequirements;
+
     /**
      * To validate Sharesheet API and API behavior works as intended UI test sare required. It is
      * impossible to know the how the Sharesheet UI will be modified by end partners so these tests
@@ -129,6 +132,10 @@
         mDevice = UiDevice.getInstance(mInstrumentation);
         mAutomation = mInstrumentation.getUiAutomation();
 
+        // The the device resolution is too low skip the unneeded init
+        mMeetsResolutionRequirements = meetsResolutionRequirements();
+        if (!mMeetsResolutionRequirements) return;
+
         mActivityManager = mContext.getSystemService(ActivityManager.class);
         mShortcutManager = mContext.getSystemService(ShortcutManager.class);
         PackageManager pm = mContext.getPackageManager();
@@ -199,6 +206,7 @@
      */
     @Test
     public void bulkTest1() {
+        if (!mMeetsResolutionRequirements) return; // Skip test if resolution is too low
         try {
             launchSharesheet(createShareIntent(false /* do not test preview */,
                     0 /* do not test EIIs */,
@@ -223,6 +231,7 @@
 
     @Test
     public void bulkTest2() {
+        if (!mMeetsResolutionRequirements) return; // Skip test if resolution is too low
         try {
             addShortcuts(1);
             launchSharesheet(createShareIntent(false /* do not test preview */,
@@ -248,6 +257,7 @@
      */
     @Test
     public void contentPreviewTest() {
+        if (!mMeetsResolutionRequirements) return; // Skip test if resolution is too low
         try {
             launchSharesheet(createShareIntent(true /* test content preview */,
                     0 /* do not test EIIs */,
@@ -431,6 +441,26 @@
     Setup methods
      */
 
+    /**
+     * Included CTS tests can fail for resolutions that are too small. This is because
+     * the tests check for visibility of UI elements that are hidden below certain resolutions.
+     * Ensure that the device under test has the min necessary screen height in dp. Tests do not
+     * fail at any width at or above the CDD minimum of 320dp.
+     *
+     * Tests have different failure heights:
+     * bulkTest1, bulkTest2 fail below ~680 dp in height
+     * contentPreviewTest fails below ~640dp in height
+     *
+     * For safety, check against screen height some buffer on the worst case: 700dp. Most new
+     * consumer devices have a height above this.
+     *
+     * @return if min resolution requirements are met
+     */
+    private boolean meetsResolutionRequirements() {
+        final Point displaySizeDp = mDevice.getDisplaySizeDp();
+        return displaySizeDp.y >= 700; // dp
+    }
+
     public void addShortcuts(int size) {
         mShortcutManager.addDynamicShortcuts(createShortcuts(size));
     }