Home » All, Mobile Software, Mobile Tips » Block Unwanted calls on your N900

Block Unwanted calls on your N900

Update: Thanks to Giacomo‘s help we’ve got a better script which takes the phone numbers to block from a text file.

Something which I really missed on the N900 was a good call blocking software. After being hounded day after day by credit card sales people and people trying to give me low interest loans, I had to find a way to get this done. A bit of hunting on the web and picking up a little bit of Python, I hacked a working solution to this problem. It’s not a perfect solution, and is a hack job, but it should do till someone writes up a good application to handle unwanted callers.

Step 1: Install Dependencies on your phone
Before we go to the call block script, you’ll need to install a few apps on your phone. First you’ll need to gain root access to your phone, so head over to your App Manager and install rootsh. If you can’t find it in your app manager, head over to this URL and download rootsh – maemo.org/downloads/product/Maemo5/rootsh/

If you haven’t installed a Python application in your phone, you’ll have to install the Python runtimes on your device. If you haven’t installed the extras-devel repositories, check for the Maemo 5 instructions here – pymaemo.garage.maemo.org/installation_device.html. Once you have that repository  installed on your phone, search and install maemo-python-device-env to install python.

Step 2: Download and move the Script to your phone
Once that’s installed, download this zip file and extract the python script from the file and save this file your device under Nokia N900/ as callblock.py .

Step 3: Create the Block list with numbers you’d like to block
Before running this script, you’ll need to create a text file with the numbers you need to block. Add as many numbers you’d like to block on a new line. The file contents should like like below:

+918067337555
+918067348300
+918066167590

Save this file as BlockedCallers.txt in the same location you saved the call block script. Please enter the numbers in the format you see when you get the calls, so you needn’t enter it exactly as I’ve put it up.

Step 4: Run the script on your phone
Now to start the call block script, head over to the terminal, get into the root mode by entering the following:

root

and then start the callblock application and background it:

python /home/user/MyDocs/callblock.py &

Make sure you type the command as is, with the capitalizations in MyDocs typed in, or the command will fail.

Now you’ve got the script running on your phone in the background and you can close the Terminal window. Your phone will block any calls with the numbers you’ve saved in the BlockedCallers.txt file. Anytime you want to change the numbers, you’ll have to edit the BlockedCallers.txt text file and add numbers into it. You’ll have to restart the script to get the latest edits to your block numbers active.

Also when ever you restart the phone, you’ll have to follow the last steps to restart the call block application. So remember when you restart the phone, make sure you go to the terminal and enter the following two lines into it:

root
python /home/user/MyDocs/callblock.py &

I’ve been trying to figure out how to auto-start this script, but I haven’t been successful at that yet. I’ll update you as soon as I figure that one out.

If you have more tips on how to improve this script, or know how to autostart the script when the phone boots up, let us know by commenting on this post.

Links:

Click to download the script file: Here’s the zip file with the callblock script. Download it and extract callblock.py from the zip file. Edit the number to block in the file by opening it up in a text editor  and move the saved file over to your device.

Link to Python Doc (and sources) I went though and borrowed to build this example:
PyMaemo/Phone call and SMS examples

Image Credit: via hoyasmeg on flickr

Disclaimer: We are providing this script as it, without much support. I’ve tested this for a few days on my phone and it worked as expected without any issues. We’re not responsible for any problems you may face using this script.

Share and Enjoy:
  • Twitter
  • Facebook
  • StumbleUpon
  • del.icio.us
  • Reddit
  • Digg
  • Google Bookmarks
  • RSS
  • email
  • Print
  • Slashdot
  • Posterous
  • MySpace
Tags: , ,
  • If you want to start this automaticly.. Create file /etc/event.d/callblocker with next lines:

    start on started hildon-desktop
    stop on starting shutdown
    console none
    service
    script
    /etc/init.d/callblocker start
    end script

    And then file /etc/init.d/callblocker what have lines:

    #! /bin/sh
    #
    # callBlocker callBlocker is caller blocker utility
    #

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/bin/python
    NAME= CallBlocker
    DESC="advanced call blocker utility"

    startdaemon () {
    start-stop-daemon --start --quiet "$@" --pidfile /var/run/$NAME.pid --exec ${DAEMON} -- /home/user/MyDocs/callblock.py&
    }

    stopdaemon () {
    start-stop-daemon --stop --quiet "$@" --pidfile /var/run/$NAME.pid --exec ${DAEMON}
    }

    test -x $DAEMON || exit 0

    set -e

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    startdaemon
    echo "${NAME}."
    ;;
    stop)
    echo -n "Stopping $DESC: "
    stopdaemon --oknodo
    echo "${NAME}."
    ;;
    restart)
    echo -n "Restarting $DESC: "
    stopdaemon || true
    sleep 1
    startdaemon
    echo "${NAME}."
    ;;
    # restart-if-running)
    # echo -n "Stopping $DESC if it is running: "
    # if start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid --exec ${DAEMON} ; then
    # echo "${NAME}."
    # echo -n "Restarting $DESC: "
    # startdaemon
    # echo "${NAME}."
    # else
    # echo "(not running)."
    # fi
    # ;;
    *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart}" >&2
    exit 1
    ;;
    esac

    exit 0
  • nA ni sivAm
    Hi Jussi, thanks heaps for the upstart script. Though i can manually run callblocker event upstart script by running "start callblocker", but i am unable to get it running automatically on boot. I do have placed the 2 callblocker files in init.d and event.d resp. the py script is actually again named as callblocker.py. but i guess as long as this filename is update appropriately in the init.d start script, it should be fine right? initctl shows the presence of the callblocker. am not sure if there is anything to do about this Upstart thing. Please help.
  • vinuthomas
    Thanks Jussi. That really helped.
  • DragoVe
    Allow only contacts number would be great feature, also some widget checking if the script is running or not... sometimes i reboot and i forget to run it... Great code, great work guys... thanks !!!
  • MrL
    hi,

    first off kudos for the code =)

    does anyone have an idea if it would be possible to block unknown numbers? simply i was to block all callers from phones that don't release their call ID.

    thanks

    MrL
  • @MrL @Nicolas Will let you know when I figure that out.
    @Giacomo any way to block calls without a number?
  • I don't know :) but I put the request in the tracker and I'll give it a go ( https://garage.maemo.org/tracker/index.php?func... ). To anyone reading this: please use the tracker at https://garage.maemo.org/tracker/?group_id=1404 to log feature requests and bugs.
  • If I figure out how to autostart the script, I could write a proper interface for it and put it up on garage.maemo.org. Is it ok for you ?
  • Yes, please do. That would be great if you could put that up. Makes things easier for all of us :)
  • It's 99% ready and will go up on https://garage.maemo.org/projects/callblocker/ later today or tomorrow. I've written a proper GUI to edit the blacklist and enable/disable the blocklist on the fly. The only thing I'm missing is a way of dynamically reload the blocklist, at the moment it requires a reboot.
  • It's up :) I've built a debian package that needs real testing, as I've done all the work in the scratchbox emulator until now.

    The reloading issue was solved with a basic dbus service, so now adding / deleting numbers should be reflected on-the-fly, which I think is cool :)

    I've got a few more features in mind (block specific contacts from addressbook etc)...
  • The callblock functionality doesn't seem to work on my phone with the build I downloaded. I can add and remove numbers but the calls don't get blocked for some reason.
    I've tried exiting the app and starting it again, and stil doesn't block it.

    I've added a bug on the tracker site regarding this.
  • Mmmh, something went wrong with the upload in Google Chromium (?), I've just re-done it in Firefox, re-downloaded the file, and now the package seems fine.
  • Tried download the deb files for the project and I was getting 0 byte files from the server. I tried to download from: https://garage.maemo.org/frs/?group_id=1404&rel...
  • George
    The script works with only one problem, how do I remove the block for a number. I tried editing the BlockedCallers.txt file and even rebooting the phone but this does not solve the problem
  • @George, Which version of the script did you use, the older one or the new one posted above?
    If you installed the older version, the numbers to block are in the callblock.py itself. So you'll have to remove it from there.

    If you are using the newer one, try this:
    1. Shutdown the phone.
    2. Start it up
    3. See if the call block has been removed. It should at this point, since the callblock script is not yet active.
    4. Start the call block script now and see if the number you removed is still blocked. If it is, send me a copy of the script you are using to vinuthomas(at)mynokiaworld.com
  • Nicolas
    how can I block anonyous calls?
  • Jason Hammons
    Regarding automation, you maybe able to use SES (like cron and @reboot). See here: http://maemo.org/packages/package_instance/view...
  • Thanks will try that out.
  • Zubair
    any one can help me i have done all the step to block call when i will do final step to run application
    root
    python /home/user/MyDocs/callblock.py &
    nothing is doing no application is starting i am still in x-terminal application
  • Once you run python /home/user/MyDocs/callblock.py & in the terminal, the application is already running in the background. Any calls from numbers you had listed in the text file will automatically be blocked.
  • Juha Linnanen
    It works! Although one thing is annoying: it still shows a call missed dialog - it would be nice if this could be ignored as well!
  • nokix
    what happens to the callers of the blocked calls? do they get a busy ringtone or get diverted to voicemail?
  • They get a busy tone if you don't have voicemail divert setup.
  • manss thomas
    Anyone try to do this with sms's ?
    to blacklist sms and copy it to some .txt file or other sms folder?

    Any battery issues with running this script ?

    thanks
  • @Giacomo Thanks for the improved script. the comment system stripped out the whitespaces. I'll update the artice with your improved script.
  • Great stuff! :D

    It would be even better to read those numbers from a simple text file, so that one doesn't need to mess with the script each time he wants to add a new number... considering Python is whitespace-sensitive, it's very easy to break a script. Also, I don't see the point in looping through the list on each call :)
    I'd make it something like this (let's hope this comment system respects whitespace...):

    #! /usr/bin/python
    import os
    import gobject, dbus
    from dbus.mainloop.glib import DBusGMainLoop

    blocklistFile = '/home/user/MyDocs/BlockedCallers.txt'

    def handle_call(obj_path, callernumber):
    global blocklist
    if callernumber in blocklist:
    print 'I have to block %s' %callernumber
    bus = dbus.SystemBus()
    callobject = bus.get_object('com.nokia.csd.Call', '/com/nokia/csd/call/1')
    smsiface = dbus.Interface(callobject, 'com.nokia.csd.Call.Instance')
    smsiface.Release()

    blocklist = []
    if os.path.exists(blocklistFile):
    try:
    blFile = open(blocklistFile,'rb')
    blocklist = [num.strip() for num in blFile.readlines()]
    blFile.close()
    except Exception:
    print "Blocklist missing, should be at " + blocklistFile

    DBusGMainLoop(set_as_default=True)
    bus = dbus.SystemBus()
    bus.add_signal_receiver(handle_call, path='/com/nokia/csd/call', dbus_interface='com.nokia.csd.Call', signal_name='Coming')
    gobject.MainLoop().run()
  • Something I miss is the contrary, auto answer.
    been trying with python api but get permission denied calling .Answer()
    didn't you try it with dbus?
  • Nope, didn't try that out yet.
  • Awesome work sir!
blog comments powered by Disqus
Copyright © 2009 · My Nokia World · All Rights Reserved · Posts · Comments
Designed by Theme Junkie · Powered by WordPress