Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
minotauri
Old
(Last edited by minotauri; 10th November 2010 at 07:03 AM.)
#1  
Senior Member - OP
Thanks Meter 120
Posts: 500
Join Date: Jun 2008
Location: Seattle, WA

 
DONATE TO ME
Default [MOD] Ad Blocking on Start-Up [Updated 11/09/2010]

update: This method is for use with Temp-Root with Visionary app. For permanent root, you can just use the adfree app, which is free in the market. Alternatively, you can still use the manual temp-root method with permanent root if you don't want an extra app. Just run the adblock-startup.sh file once, and then use the wget script whenever you want to do an update of the hosts file!


After trying out a few things to get ad free working on startup, I was able to get it going without actually using the app. I used the basic concept of the app, but basically am performing it in command lines.

For this, I used GScripts to run/edit scripts, and Visionary to do a temp-root.

If you want to skip all of this, and go to a completely automated script, see updates at bottom.

First, create a script, adblock-wget.sh, to download the latest hosts file which blocks certain sites. It pulls the file from a website that contains updated hosts files and stores it in /data/data/:

##adblock-wget.sh##
Code:
wget http://209.68.48.119/winhelp2002/hosts.txt -O /data/data/hosts
This can be done in GScripts, and run every couple days to get the latest copy. Make sure you have SU checked in the script.

Second, we need to make another script, adblock-startup.sh which removes the existing hosts file in /system/etc/ and then create a symlink to the hosts file we just obtained on the internet in /data/data/

##adblock-startup.sh##
Code:
mount -o remount,rw /dev/block/mmcblk0p25 /system
rm /etc/hosts
ln -s /data/data/hosts /system/etc/hosts
mount -o remount,ro /dev/block/mmcblk0p25 /system
finally, you'll need to add this script to visionary.sh. if you created it in gscripts, one easy method is to long press the script in the menu, and save to SD. it'll be placed in your /sdcard/gscript/ folder.

to place this newly created script in visionary.sh, open up your current visionary.sh file, and place this line in it:

##visionary.sh##
Code:
sh /sdcard/gscript/adblock-startup.sh #change to correct directory
busybox killall system_server #this hot reboot is optional
the last line in that script performs a quick reboot, which retains temp-root and hopefully clears the DNS caches if you are still seeing ads pop up.

- - - - -

[UPDATE 11/03/2010]
I added the scripts in a zip file attached.

[update 11/04/2010]
if you dont want to manually update, you can just add the wget function into the installation script shown below. This will download the latest ad block updates at start-up, so you will not need to manually update later.

## adblock.sh ##
Code:
wget http://209.68.48.119/winhelp2002/hosts.txt -O /data/data/hosts
mount -o remount,rw /dev/block/mmcblk0p25 /system
rm /etc/hosts
ln -s /data/data/hosts /system/etc/hosts
mount -o remount,ro /dev/block/mmcblk0p25 /system
for this method, just place the same info in visionary.sh:

##visionary.sh##
Code:
sh /sdcard/gscript/adblock.sh
busybox killall system_server
replace the location to where you end up putting adblock.sh.

working example files are attached.

- - - - -

please note that you can change some of these steps to fit what other items you have running at startup.

if you're able to find a better method to perform this, please let me know! I was unable to run these commands directly within visionary.sh, so i had to make these links.

Thanks!

credits go to "Microsoft MVPs" for maintaining the HOSTS ad blocking file, delta_foxtrot2 who discovered and made the AdFree app
Attached Files
File Type: zip adblock-original.zip - [Click for QR Code] (383 Bytes, 89 views)
File Type: zip adblock-update1104.zip - [Click for QR Code] (245 Bytes, 190 views)
File Type: zip visionary.zip - [Click for QR Code] (272 Bytes, 91 views)
PHONE: Google LG Nexus 4, iPhone
TABLET: iPad (3rd Gen)

Twitter: http://www.twitter.com/antnguyen
 
Shambala001
Old
#2  
Senior Member
Thanks Meter 0
Posts: 117
Join Date: Aug 2009
Location: Tampa
Nice write up, I finally got it working using root explorer and doing the steps manually, but was too lazy to script it haha, good work though
Retired
G1 - Bronze
G2

Current
Nexus 4

 
Dalamak
Old
#3  
Dalamak's Avatar
Senior Member
Thanks Meter 6
Posts: 297
Join Date: Dec 2008
Location: Newark
Upload the script file for us

Sent from my T-Mobile G2 using XDA App
Eten M800
MWG Zinc II
BB Flip
G1
Mytouch 3g
Touch Pro 2
HD2
HTC S411 (Star Trek)
G2
Moto Defy
 
minotauri
Old
#4  
Senior Member - OP
Thanks Meter 120
Posts: 500
Join Date: Jun 2008
Location: Seattle, WA

 
DONATE TO ME
Quote:
Originally Posted by Dalamak View Post
Upload the script file for us

Sent from my T-Mobile G2 using XDA App
done. check the first post.

you can also be sporty and use the wget function at startup too.
PHONE: Google LG Nexus 4, iPhone
TABLET: iPad (3rd Gen)

Twitter: http://www.twitter.com/antnguyen
 
rhcp0112345
Old
#5  
Account currently disabled
Thanks Meter 113
Posts: 1,589
Join Date: Jun 2010
Location: North Carolina

 
DONATE TO ME
For those of you who have a problem with visonary.sh locking your phone up.

Here is a gscript version.

Code:
# Overclock the CPU
insmod /data/local/vision_oc.ko pll2_l_val=73
insmod /data/local/tun.ko

# No Ads thanks XDA
rm /data/data/hosts
wget http://209.68.48.119/winhelp2002/hosts.txt -O /data/data/hosts
mount -o remount,rw /dev/block/mmcblk0p25 /system
rm /etc/hosts
ln -s /data/data/hosts /system/etc/hosts
mount -o remount,ro /dev/block/mmcblk0p25 /system
 
dyndragon
Old
#6  
Senior Member
Thanks Meter 60
Posts: 525
Join Date: Jan 2007
Does this actually work? I've tried hot-rebooting the phone (retaining root), and I still get ads. How does this differ from using visionary, running ad free, and hot booting?

The problem I'm seeing is that it doesn't seem like a hot reboot clears the DNS cache.
 
minotauri
Old
(Last edited by minotauri; 4th November 2010 at 08:07 PM.)
#7  
Senior Member - OP
Thanks Meter 120
Posts: 500
Join Date: Jun 2008
Location: Seattle, WA

 
DONATE TO ME
Quote:
Originally Posted by dyndragon View Post
Does this actually work? I've tried hot-rebooting the phone (retaining root), and I still get ads. How does this differ from using visionary, running ad free, and hot booting?

The problem I'm seeing is that it doesn't seem like a hot reboot clears the DNS cache.
it sometimes block ads, sometimes does not. one, you might have to clear the caches in the apps you use as well. and two, some ads (presumably newer) arent blocked in the hosts file either.

this is not different than using adfree at all. it uses the same hosts file and same symlink technique for htc phones. i just tried to make it work automated on startup.
PHONE: Google LG Nexus 4, iPhone
TABLET: iPad (3rd Gen)

Twitter: http://www.twitter.com/antnguyen
 
rhcp0112345
Old
#8  
Account currently disabled
Thanks Meter 113
Posts: 1,589
Join Date: Jun 2010
Location: North Carolina

 
DONATE TO ME
works here.
 
minotauri
Old
#9  
Senior Member - OP
Thanks Meter 120
Posts: 500
Join Date: Jun 2008
Location: Seattle, WA

 
DONATE TO ME
Default update

updated original post with a newer "self-healing" start up script, which will automate the entire process after running visionary root.
PHONE: Google LG Nexus 4, iPhone
TABLET: iPad (3rd Gen)

Twitter: http://www.twitter.com/antnguyen
 
blk_jack
Old
#10  
blk_jack's Avatar
Recognized Developer
Thanks Meter 2381
Posts: 1,672
Join Date: Jun 2010
Location: Toronto
How come in the script you delete /etc/hosts but symlink to /system/etc/hosts ? Excuse my ignorance

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...

XDA PORTAL POSTS

Boot Animation Paradise for your Android Device

The default boot animations on any device, no matter whichmanufacturer, are generally pretty … more

Flash Custom ROM and Recovery to Samsung Galaxy S 4

After reading about Dan Rosenberg’s bootloader exploit for the Samsung Galaxy S 4,I … more

Windows-Based Multi-Tool for the Sony Xperia U

If you are a flashaholic and an owner of the Sony Xperia U, you may be interested in the … more