Block ads on your Android phone (2010-04-15)

Search This thread

cauli

Senior Member
Mar 7, 2010
320
0
A bit off topic, I have netcounter but sadly it only shows total data usage per period, I'm looking for an app that can tell me data usage PER application, cause not even browsing (only gmail sync, twitter sync (per 1hr), fb sync (per 3hrs) I get to about 90MB used per day. I want to know what app is using up my bw :(
SpareParts claims to do this but that is the one feature of it which has never worked for me on my gsm Hero running MCR 3.2. It does work for some people though, so probably relies on an OS or hardware feature I'm lacking.
 

Airbag888

Senior Member
May 5, 2010
326
63
It's working on my N1 Thanks. It seems to have it under battery usage but when you pick details of every app listed (I dont see a lot) it the amount of bytes in and out so I suppose that's a start.
It also seems that there's a record of what app's been using the network prior to install, so I suspect there's a sort of log somewhere. I wonder if it'd be possible to know where and get an app that reads it to give details.
 

petsasj

Retired Recognized Developer
Mar 22, 2010
1,605
1,501
35
Athens
I know this question might sound stupid, but i'll ask it anyway.

Does this effect persist through ROM changes (+wipes)?

I believe the answer is no (pretty sure it is), but what the heck :)

Thanks!
 

H3g3m0n

Senior Member
Sep 15, 2009
60
16
It might be worth while changing the default host from 127.0.0.1 to 0.0.0.0 (actually I think technically it's an 'any' address, but that only makes sense for binding a listening socket as you can connect to 'any' its dropped).

127.0.0.1 is the loopback address which means the browser will try to make a connection to the local system and waste some time. The latter is the null ip address which should just get nuked before any connection attempt.
 
Last edited:

phaelox

Senior Member
Feb 28, 2009
119
17
Great!! :)

There is any possibility to apply the changes without rebooting?.
When adfree update the hosts file, reboot isn't necessary.

Well, what happens is same as with adfree: the hosts file is replaced. Just to be on the safe side, I said reboot. Very well possibly it will work straight off, without rebooting.
I know this question might sound stupid, but i'll ask it anyway.

Does this effect persist through ROM changes (+wipes)?

I believe the answer is no (pretty sure it is), but what the heck :)

Thanks!
You are correct, it does not persist when factory resetting or flashing new rom. The /etc directory is part of the system volume which gets wiped.
It might be worth while changing the default host from 127.0.0.1 to 0.0.0.0 (actually I think technically it's an 'any' address, but that only makes sense for binding a listening socket as you can connect to 'any' its dropped).

127.0.0.1 is the loopback address which means the browser will try to make a connection to the local system and waste some time. The latter is the null ip address which should just get nuked before any connection attempt.

As I understand it, 0.0.0.0 is a special address for interfaces that are down, and received packets sent from a (local) source not expecting a reply. Could work, but never seen anyone use it in a hosts file, which makes me wonder. No idea how TCP/IP stack would handle it. If you try it, let us know.
 
Last edited:

dazzling

Member
Apr 18, 2009
24
1
It works SO well on those annoying ads. Thanks ;)

Just in case anyone uses the terminal, the full command is as follow

Code:
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
cp hosts.for.mobile.txt /etc/hosts
mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system


it's working :)
i just change cp /sdcard/hosts.for.mobile.txt /etc/hosts
because i put txt on my sd card

thank you for the lecturing everyone :)
 

stegg

Senior Member
Aug 29, 2008
501
57
Milan
sorry for my noobness...

using my rooted legend, with usb debug mode.
I enter the first ADB command (mount), it's ok, but the second one
adb push hosts.for.mobile.txt /etc/hosts
gives this error
failed to copy 'hosts.for.mobile.txt' to '/etc/hosts': Directory not empty

what can I do to copy this file? :)

btw the phone reboots itself after that error
 

cryshop

Senior Member
Feb 25, 2010
303
99
Ho Chi Minh
sorry for my noobness...

using my rooted legend, with usb debug mode.
I enter the first ADB command (mount), it's ok, but the second one
adb push hosts.for.mobile.txt /etc/hosts
gives this error
failed to copy 'hosts.for.mobile.txt' to '/etc/hosts': Directory not empty

what can I do to copy this file? :)

btw the phone reboots itself after that error

I got this message also, failed
 

stegg

Senior Member
Aug 29, 2008
501
57
Milan
done!

same here... any ideas?

I successfully copied the hosts file on the legend.
OF COURSE you must be knowing rooting procedures and recovery and console command, and whatever happens it's not my fault.

instructions:

1) have your legend rooted, of course
2) put a suited hosts.txt file in the etc folder of your recovery directory, e.g. "C:\r4-legend-root\files\hosts.txt" --- in this way we 'll temporarily have the hosts.txt file into your phone
3) enter into recovery mode
4) in your administrator console on your pc, type:

Code:
adb shell mount -o rw -t yaffs2 /dev/block/mtdblock3 /system
adb shell cp /etc/hosts /system/etc/hosts 
adb shell mount -o ro -t yaffs2 /dev/block/mtdblock3 /system

(the latter command returns "system busy" to me, maybe yours won't)
5) wait a couple of seconds, just for sake, then reboot your phone

et voilà :D at next reboot, the new hosts file works!

cool people may want to set hosts file properties, but I didn't do.
after all, at the next reboot the system is still read-only so it shouldn't be necessary to set permissions
 
Last edited:

xlxl

Senior Member
Nov 4, 2009
150
0
sorry for my noobness...

using my rooted legend, with usb debug mode.
I enter the first ADB command (mount), it's ok, but the second one
adb push hosts.for.mobile.txt /etc/hosts
gives this error
failed to copy 'hosts.for.mobile.txt' to '/etc/hosts': Directory not empty

what can I do to copy this file? :)

btw the phone reboots itself after that error

same for me
 
Problems Here

Hi everyone,

So I uploaded the hosts file to /etc, rebooted and cleared browser cache and still seeing ads in my apps.

Can anyone help?

I copied the hosts file using root explorer, do I need to set permissions to the hosts file?

I am running a stock Milestone ROM, rooted of course and used to use AdFree but it stopped working.

TiA,
Szadzik
 
Last edited:

ionstorm3

Senior Member
Jun 5, 2010
51
12
Detect ad servers

Hi I was wondering how to detect ad servers on android. In OSX there is an app called Little Snitch that will detect outgoing connections and report the url. I was wondering if there is a way to detect outgoing connections' urls in android. If so then I could add those to my phone's hosts file.
 

tbrummell

Senior Member
Sep 27, 2007
414
38
Ottawa
Samsung Galaxy S22
Hi I was wondering how to detect ad servers on android. In OSX there is an app called Little Snitch that will detect outgoing connections and report the url. I was wondering if there is a way to detect outgoing connections' urls in android. If so then I could add those to my phone's hosts file.

Logcat.

The message you have entered is too short. Please lengthen your message to at least 10 characters.
 

ionstorm3

Senior Member
Jun 5, 2010
51
12
Umm, I looked at logcat and saw the log file for my phobne, but i do not see any urls. The only 3 urls I see in the log file are from google. Where are the urls for the ads in the apps? I installed apps with ads in them just to test out the log file, but I dont see the urls that the adds are requesting. How exactly do I find the urls or IP addresses?
 

pulser_g2

Admin Emeritus / Senior Recognized Developer
Nov 27, 2009
19,544
11,630
Umm, I looked at logcat and saw the log file for my phobne, but i do not see any urls. The only 3 urls I see in the log file are from google. Where are the urls for the ads in the apps? I installed apps with ads in them just to test out the log file, but I dont see the urls that the adds are requesting. How exactly do I find the urls or IP addresses?

I don't think you will necessarily see the URLs of the ads in logcat. Usually only google-related stuff writes to logcat the URLs (or at lease it's mainly native apps in my experience).

I think the best way to do this would be to connect by WiFi, and use a protocol analyser on a PC (dunno if one exists for android) to get the URL out of the http packets.

But is it worth it? It's a lot of work to remove a couple of little adverts.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    AdFree is a fantastic program created by XDA user delta_foxtrot2 (see this thread in the G1 forum) to facilitate using your hosts file to block ad servers. This makes it extremely easy. Of course you will need root access!


    Unfortunately I found some ads still weren't blocked and the last update to the AdFree hosts file happened 2010-02-27. So I decided to update the hosts file myself. I merged the hosts files from adfree/mvps/yoyo and added a bunch of mobile ad providers I've found myself. The list is free of duplicates and comments, so as to keep it as small as possible (it still amounts to about 635 kB).

    To install this hosts file, you still need root access obviously:

    1. download the zip
    2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
    3. open a command prompt
    Code:
    adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
    adb push hosts.for.mobile.txt /etc/hosts
    adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

    You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).


    As for ethical discussions on blocking ads for free apps, blah. I don't so much have a problem with ads, as I do with the personal data that gets send to the ad providers. I'm talking about location data and whatever else they might want to know about my device and what I'm running ("analytics" is a fancy name for "we want to find out as much about you as we possibly can get away with").

    Anyway.. use it, don't use it, up to you.

    Last updated

    15-4-2010 23:23 (20808 hosts blocked)


    .
    5
    Hello, since this is the top search result for this topic on Google I'd thought I'd share an update. This is a simple method:

    1. Boot into clockworkmod recovery
    2. partitions > mount /system
    3. adb push hosts /system/etc/hosts
    4. adb reboot

    No need to play with remount and permissions in recovery. Working on CM7 RC2 on HTC Aria. I have updated the hosts file using the sources in the comments as of March 8, 2011.

    Edit: Put mobile advertisers from original list back in and removed duplicates.
    2
    I've shamelessly stolen from the hosts files in this thread and then added my own to make an up-to-date list that mainly works for me.

    The file is sorted, (with the exception of the localhost entry), with duplicates removed.
    2
    caps are important - yes, however, it is strange that the hosts file is HOSTS on your Android ROM... but I guess nothing is impossible...

    @No-Frost: If you have Terminal Emulator and some Superuser app for granting root privileges, you can use the following:

    You need to place the hosts file on your SD card to begin with (in this example, the hosts file is: /mnt/sdcard/hosts.final)

    Next, you need to mount the filesystem in read-write mode, as it is read-only by default

    su
    mount -o remount,rw /dev/block/mtdblock3 /system
    mv /etc/hosts /etc/hosts.bak
    cp /mnt/sdcard/hosts.final /etc/hosts
    chmod 644 /etc/hosts
    mount -o remount,ro /dev/block/mtdblock3 /system
    ls -l /etc/hosts


    That should move the hosts.final file from the root of your SD card, into the /etc directory, and apply the filename: hosts

    Be weary of filenames and foldernames under linux - they are case-sensitive... you don't want System or ETC, etc.

    Once you've executed the last line in the script ls -l /etc/hosts, you should be able to verify that the hosts file exists, with the correct access rights.

    Maybe reboot at this point.

    Quit Terminal Emulator, open your browser, maybe clear the cache in the browser, and open one of the ad-servers listed in your hosts file, e.g.:
    http://00fun.com
    If the page fails to load, then everything worked!

    If you still get ads in apps or websites after the above test succeeded, then it could be that the specific app or website is sourcing it's ads from another host that is not yet in the hosts file, or via some other means...
    2
    Finally got it to work.

    Now there is no way I got this working from terminal app, adb + phone booted or default recovery mode (traingle screen). However if you boot into clockwork recovery mode, manually mount system and sdcard and than use the commands from this topic it will work.