Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2489eaa authored by Ben Reich's avatar Ben Reich
Browse files

Don't expect PHOTOPICKER to appear on devices without it

The TrampolineActivity currently expects the ACTION_PICK_IMAGES to be
available on the device otherwise it opens up DocumentsUI. The way
mainline works in tests is it flashes the base image then the module on
top, so that means for DocsUI tests it sometimes doesn't have
Photopicker available in the environment. Update the test to ensure it
tests the appropriate combination and update the strings so this
information is readily available when debugging the tests.

Bug: 407678392
Test: atest com.android.documentsui.TrampolineActivityTest
Flag: com.android.documentsui.flags.redirect_get_content_ro
Change-Id: I5dd83c56702d9c6d1d813644d4ae0264180edf80
parent 31cd2012
Loading
Loading
Loading
Loading
+27 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.documentsui
import android.content.Intent
import android.content.Intent.ACTION_GET_CONTENT
import android.os.Build.VERSION_CODES
import android.os.ext.SdkExtensions
import android.platform.test.annotations.RequiresFlagsEnabled
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
@@ -199,23 +200,41 @@ class TrampolineActivityTest() {

            context.startActivity(intent)

            val bySelector = when (testData.expectedApp) {
                AppType.PHOTOPICKER -> By.pkg(PHOTOPICKER_PACKAGE_REGEX)
            // Photopicker was introduced into the platform in Android T, however it was backported
            // to R via SdkExtensions in MediaProvider. Ensure that the target device has the
            // backport otherwise fallback to DocumentsUI.
            val isPhotopickerAvailable = SdkExtensions.getExtensionVersion(VERSION_CODES.R) >= 2
            val bySelector = when {
                testData.expectedApp == AppType.PHOTOPICKER && isPhotopickerAvailable -> By.pkg(
                    PHOTOPICKER_PACKAGE_REGEX
                )
                else -> By.pkg(DOCUMENTSUI_PACKAGE_REGEX)
            }

            val builder = StringBuilder()
            builder.append("Intent with mimetype ${testData.mimeType}")
            if (testData.extraMimeTypes.isPresent) {
                builder.append(
                    " and EXTRA_MIME_TYPES of ${
                val extraMimeTypes = when {
                    testData.extraMimeTypes.get().isNotEmpty() -> {
                        testData.extraMimeTypes.get().joinToString(", ")
                    }"
                    }
                    else -> "empty array"
                }
                builder.append(
                    " and EXTRA_MIME_TYPES of ($extraMimeTypes)"
                )
            }
            if (testData.expectedApp == AppType.PHOTOPICKER && !isPhotopickerAvailable) {
                builder.append(
                    " didn't cause ${AppType.DOCUMENTSUI} to appear " +
                        "(${AppType.PHOTOPICKER} is expected, but is not available in this " +
                        "environment) after ${UI_TIMEOUT}ms"
                )
            } else {
                builder.append(
                    " didn't cause ${testData.expectedApp.name} to appear after ${UI_TIMEOUT}ms"
                )
            }

            assertNotNull(
                builder.toString(),