Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ val isEmulatorWithFakeFrontCamera: Boolean
get() = Build.HARDWARE == "ranchu" &&
(Build.VERSION.SDK_INT == 28 || Build.VERSION.SDK_INT == 34)

val compatMainActivityExtras: Bundle?
/**
* Returns the compat extras for MainActivity.
*
* These extras are used to work around issues on specific devices or emulators.
*/
internal val compatMainActivityExtras: Bundle?
get() {
val extras = Bundle()
if (isEmulatorWithFakeFrontCamera) {
Expand All @@ -73,9 +78,19 @@ val compatMainActivityExtras: Bundle?
extras.putString(MainActivity.KEY_DEBUG_SINGLE_LENS_MODE, "back")
}

return if (extras.size() == 0) null else extras
return extras.takeIf { !it.isEmpty() }
}

/**
* Merges the provided [extras] with the compat extras for MainActivity.
*
* @param extras The extras to merge with the compat extras.
* @return The merged bundle, or null if there are no extras.
*/
fun mergeWithCompatExtras(extras: Bundle?): Bundle? {
return compatMainActivityExtras?.apply { extras?.let { putAll(it) } } ?: extras
}

val debugExtra: Bundle = Bundle().apply { putBoolean("KEY_DEBUG_MODE", true) }
val cacheExtra: Bundle = Bundle().apply { putBoolean("KEY_REVIEW_AFTER_CAPTURE", true) }

Expand Down Expand Up @@ -188,7 +203,7 @@ inline fun runMainActivityScenarioTest(
extras: Bundle? = null,
crossinline block: ActivityScenario<MainActivity>.() -> Unit
) {
val activityExtras = compatMainActivityExtras?.apply { extras?.let { putAll(it) } } ?: extras
val activityExtras = mergeWithCompatExtras(extras)
runScenarioTest<MainActivity>(activityExtras, block)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public-API inline function cannot access non-public-API function.

you'll need to update the visibility modifiers of this or mergeWithCompatExtras

}

Expand Down Expand Up @@ -230,7 +245,7 @@ inline fun runMainActivityScenarioTestForResult(
extras: Bundle? = null,
crossinline block: ActivityScenario<MainActivity>.() -> Unit
): Instrumentation.ActivityResult {
val activityExtras = compatMainActivityExtras?.apply { extras?.let { putAll(it) } } ?: extras
val activityExtras = mergeWithCompatExtras(extras)
return runScenarioTestForResult<MainActivity>(intent, activityExtras, block)
}

Expand Down
Loading