We have moved to a new Sailfish OS Forum. Please start new discussions there.
7

adblock via /etc/hosts on XA2/AlienDalvik v8

asked 2019-11-01 16:11:00 +0200

jollajo gravatar image

updated 2019-11-27 16:57:14 +0200

jiit gravatar image

To block unwanted ads I've always modified /etc/hosts with the list given by winhelp2000.com. To also block the ads in Android apps we also need to modify the hosts file on the android side. For Andorid 4.4 (Jolla 1/C, Xperia X) you could copy this to /system/etc/hosts and /opt/alien/system/etc/hosts.

On the newer Version of AlienDalvik that runs on XA2 the file is only accessible within the lxc container and unfortunately the filesystem is readonly there. Is there a way to modify that file without unpack-modify-repack the filesystem (I don't dare to do so.)? Is there another location we could keep the list?

Do you have any other idea?

edit retag flag offensive close delete

3 Answers

Sort by » oldest newest most voted
4

answered 2019-11-02 10:07:55 +0200

lethe gravatar image

You can override the android hosts file without re-packing the filesystem image by modifying the LXC config.

Simply edit the file /var/lib/lxc/aliendalvik/extra_config as root and add following line:

lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0

This has the added benefit, that it should survive aliendalvik updates (and if it doesn't, it is at least easier to restore).

edit flag offensive delete publish link more

Comments

Thanks, this worked for me on my Xperia XA2 Ultra with SFOS 3.3.0.16

Direc ( 2020-05-17 11:02:13 +0200 )edit
1

answered 2019-11-01 20:00:19 +0200

olf gravatar image

updated 2020-09-13 04:33:25 +0200

There iwas no need to copy /etc/hosts to the Android side for the AOSP 4.x based AlienDalviks (Jolla 1, Jolla C, Xperia X) for ad-blocking:
Simply use Defender to manage /etc/hosts, which is effective for Android apps, too.

While I have no AOSP 8 based AlienDalvik, I wonder why the lxc-containerisation would change that.
Can you please check with Defender.

Edit (2020-09-13): Meanwhile Defender turned out to prevent Xperia 10s and XA2s from booting and it has become unmaintained for long. Use this answer for these and any other device with the AOSP8-based AlienDalvik.

edit flag offensive delete publish link more

Comments

1

This won't work on AlienDalvik 8, as the android environment is completely separated from the host within its LXC container. I think previous AlienDalvik releases used the DNS server listening on 127.0.0.1 provided by connman (hence /etc/hosts worked for android). Since from within the LXC container AlienDalvik has no access to that server, it probably uses the DNS server IP retrieved from DHCP, thus /etc/hosts no longer works (the container has its own namespace and loopback interface, so 127.0.0.1 are not connected on the host & android system).

lethe ( 2019-11-02 09:55:21 +0200 )edit
1

just checked a few websites full of ads and they look very similar (only few or no ads) on native and Android browsers.

So it seems that Android apps are influenced by native /etc/hosts

I was hoping to get rid of ads within Android apps but it seems they're directly fed by google.

jollajo ( 2019-11-02 23:15:39 +0200 )edit

My results of (admittedly very limited) testing on my XA2 were:

  • editing /etc/hosts did nothing for android apps
  • replacing /system/etc/hosts by repacking system.img worked both for blocking browser as well as in-app ads (served by google)
  • editing the LXC config as described above worked just as well
lethe ( 2019-11-04 02:25:18 +0200 )edit

Well @lethe,

Can you please check with Defender.

olf ( 2019-11-04 21:48:46 +0200 )edit

That's what I used, however I do not see why that would matter...

Defender doesn't do any black magic, all it does is gather blocklists from multiple source, merge them and write them to /etc/hosts, /system/etc/hosts & /opt/alien/system/etc/hosts.

The last path will be skipped on AlienDalvik 8, since it does not exist and the second one doesn't matter (at least in my test).

lethe ( 2019-11-05 10:55:51 +0200 )edit
0

answered 2019-11-01 19:45:21 +0200

kan_ibal gravatar image

Check Dnscrypt on Sailfish. There is a possibility to set Blacklist to block ads at dns query level.

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
6 followers

Stats

Asked: 2019-11-01 16:11:00 +0200

Seen: 1,750 times

Last updated: Sep 13 '20