Removing advertisements from Android TV's home screen using BIND 9

I hate Marvel and I don't care about history.

Removing advertisements from Android TV's home screen using BIND 9

I've owned a Mi Box since around 2020 or so, it's a nice little device. I switched my main TV device thing to a HTPC since (and I'll soon be switching to an NVIDIA Shield as I now utterly hate the idea of modern HTPCs), but I brought the thing out for a TV at my desk so I can watch things while working at/on the computer.

But something just bothers me about Android TV nowadays. When I got this box, the home screen looked a little like this:

This was taken right after I got the Mi Box, I've adjusted the pic a bit to make it clearer.

Let's look at it now:

This was taken just now, with a Blackmagic capture card.

What the fuck is this shit, I mean the UI looks way better now but holy shit what in the actual fuck is taking the top half of my display? I don't give a single fuck about Marvel, get off my fucking screen damn. I can't even pay to remove these ads like Amazon does with their Fire series of Android devices. If the top half was shit that I actually watched, kinda like the "Play Next" section then it'd be better.

Well, it has to be getting ads from somewhere, right? Let's check my DNS logs!

Easy enough?

androidtvwatsonfe-pa.googleapis.com, eh? Let's see if this is what's causing our sadness.

smh I find new shit to watch by browsing box sets on Amazon. (post)

Looks like that is indeed it, along with androidtvchannels-pa.googleapis.com. Alright, let's block this shit!!!!

I use BIND 9 (named) for my forward-facing (internal and external) DNS at home, with Unbound as a fancy DNS-over-TLS upstream for Quad9 and CloudFlare's DNS service that serves outside records to named. I use BIND 9 as forward-facing since it has pretty nice access controls. I have three zones, one to rewrite xboxlive.com to Insignia for my original Xbox, one zone named internal for LAN that can do recursion (read: ask another upstream for DNS results), and another named external that mainly serves IPv6 PTR records (nslookup 2001:470:e19f:abc5:6355:2789:23fb:8cf8 to look up the hostname of my main computer as of writing this article).

One thing it can do is whats called "Response Policy Zones" or RPZ for short. It's an easy way to overlay results on top of others without messing around with a bunch of zone files. Well how do we set this up?

In one of the views in your named.conf file, add a response policy section that connects to a zone called "rpz-blacklist", and then setup that new "rpz-blacklist" zone.

...
view "internal" {
    ...
    response-policy {
        zone "rpz-blacklist";
    };
    
    zone "rpz-blacklist" {
        type master;
        file "rpz.zone";
    };
    ...
};
...

Now create the rpz.zone file in the directory with your zone files (mine is /var/named), and give those two domains an A record pointing to 0.0.0.0.

$TTL 7200

@       IN      SOA     komi.eternalrevolution.net.     hi.samicrusader.me. (
                                2023021901 ; Serial
                                28800      ; Refresh
                                1800       ; Retry
                                604800     ; Expire
                                86400)     ; Negative Cache TTL

@       IN      NS      komi.eternalrevolution.net.

androidtvchannels-pa.googleapis.com     IN      A       0.0.0.0
androidtvwatsonfe-pa.googleapis.com     IN      A       0.0.0.0

(replace komi.eternalrevolution.net. with your nameserver's fully qualified hostname (read: has the . at the end) and hi.samicrusader.me. with your email address with the @ replaced with a ., same fully qualified thing as with the nameserver)

Save that, and reload named (systemctl restart named.service), and try hitting one of those domains with nslookup:

rekt

Nice, those servers are now cockblocked. Now if we take a look at the home screen...

Right, we have to do some additional steps.

There's two ways to make this disappear. The first one is to just wait for the cache to expire with it failing to get new data. The second is to revert back to the older style menu, then give it a bit to figure itself out. Both of these will lead to the new launcher look but it'll have built in ads for YouTube and Google Play as placeholders.

To do this, hit up Settings > Apps > See all apps > Show system apps > Android TV Home > Clear data. Once you've cleared the data for the home app, force stop it, and press the home button to re-open the launcher.

Once the launcher loads back up, a familiar sight will appear:

Old layout. Yuck. At least there's no ads though.

Mission accomplished? I really want that new launcher though.

If you wait it out, your launcher will be upgraded to the new look, but with the placeholder ads:

Sweet!