Launch trailers with the vnd.youtube authority form SmartTube can parse
All checks were successful
review/code-claude Code APPROVE: no blocking finding
review/design-claude Design PASS: no visible change, no blocker

This commit is contained in:
justinzeus 2026-11-07 19:48:04 +01:00
parent 2b142af8d1
commit 8be769b67c
2 changed files with 8 additions and 5 deletions

View file

@ -19,21 +19,23 @@ import org.robolectric.annotation.Config
@Config(sdk = [34], application = Application::class)
class TitleTrailerTest {
private val context = ApplicationProvider.getApplicationContext<Context>()
private val url = "https://www.youtube.com/watch?v=abcdefghijk"
private val url = "https://www.youtube.com/watch?v=ab_-defghij"
@Test fun missingYoutubeHandlerStaysOnTheTitleEvenWhenABrowserExists() {
register(Intent(Intent.ACTION_VIEW, Uri.parse(url)), "test.browser")
register(Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=ab_-defghij")), "test.browser")
assertFalse(TitleTrailer(context).open(url))
assertNull(shadowOf(context as Application).nextStartedActivity)
}
@Test fun installedYoutubeHandlerReceivesAnExplicitPackageAndNoBrowserUrl() {
register(Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:abcdefghijk")), "test.youtube")
register(Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://ab_-defghij")), "test.youtube")
assertTrue(TitleTrailer(context).open(url))
val launched = shadowOf(context as Application).nextStartedActivity
assertEquals(Intent.ACTION_VIEW, launched.action)
assertEquals("test.youtube", launched.`package`)
assertEquals("vnd.youtube", launched.data?.scheme)
assertEquals("abcdefghijk", launched.data?.schemeSpecificPart)
// SmartTube (IntentExtractor.extractVideoId) takes the id from Uri.getHost() for this scheme; the opaque `vnd.youtube:ID` form yields null there.
assertEquals("ab_-defghij", launched.data?.host)
}
@Test fun nonYoutubeTrailerNeverOpensAGeneralViewHandler() {

View file

@ -17,7 +17,8 @@ class TitleTrailer(private val context: Context) {
?: source.pathSegments.takeIf { it.firstOrNull() in setOf("shorts", "embed") }?.getOrNull(1)
else -> null
} ?: return false
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:$video")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// Authority form: SmartTube's IntentExtractor reads the id from Uri.getHost(), which is null for the opaque `vnd.youtube:ID`.
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://$video")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val handler = context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
.firstOrNull { it.activityInfo.exported } ?: return false
intent.setPackage(handler.activityInfo.packageName)