Round 2 release candidate: Home, Discover, trailer, crash fix and stock screens #64

Merged
justinzeus merged 25 commits from fm/tv-round2-rc into fm/tv-round2 2026-11-07 21:14:15 +01:00
2 changed files with 8 additions and 5 deletions
Showing only changes of commit 8be769b67c - Show all commits

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)