Block Unwanted calls on your N900

Update: This article is outdated, you can download a pre-packaged Callblocker package based on the code on this page from the Maemo Garage – https://garage.maemo.org/projects/callblocker/ . You can the deb file from the project page and install it on your N900.

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 .
[ad#ga-480-break]
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.

Published by

Vinu Thomas

Vinu is a Technical Architect working on Web technologies and a mobile enthusiast, who likes trying out new gadgets and apps. You can follow him on Twitter @vinuthomas

86 thoughts on “Block Unwanted calls on your N900”

  1. 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?

      1. hi vinu thomas this is barath
        in my n900 catblock is not working. when i try to uninstall it i couldnt. please help me how to solve it. i am not well versed in computing. so please let me know the procedure in simpler way.

        1. All you need to do to uninstall is to remove the files which you placed on the phone and do a quick restart of the phone.

  2. 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?

  3. 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()

  4. 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()

  5. Pingback: Arun Vijayan
  6. 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

  7. 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!

  8. 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

    1. 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.

  9. 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

    1. 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.

  10. 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

    1. @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

  11. 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

    1. @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

        1. 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)…

          1. 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.

          2. 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.

        1. 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)…

          1. 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.

          2. 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.

  12. 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

      1. When you receive a call from “Unknown number”, the parameter callernumber is actually an empty string. So, in order to block the calls from “Unknown number” you can check whether the length of callernumber is 0. I made this small change in the script and works just fine.

  13. 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

  14. 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 !!!

  15. 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 !!!

  16. 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 “[email protected]” –pidfile /var/run/$NAME.pid –exec ${DAEMON} — /home/user/MyDocs/callblock.py&
    }

    stopdaemon () {
    start-stop-daemon –stop –quiet “[email protected]” –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

  17. 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.

  18. Hello! I’m having some trouble on final step…
    when I type

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

    my N900 give me:
    ==================
    /home/user/ # python: can’t open file ‘/home/user/MyDocs/callblock.py’: [Errno 2] No such file or directory
    ==================

    Sorry if this is dumb question, but I copied these files in many folders inside my N900 and it still doesn’t work…

    thanks in advance

  19. Don’t you have something as simple as just download and it will start working? This is for dumb like me, who does not understand anything in programming

  20. UP!!!!!!!!!!!!!!!
    plizz help !!!
    How block unknown call ???????
    to simbian have more soft to block calls and unknown call (option) !!!
    whot simbols i need screen in BlockedCallers.txt ???

  21. There’s new piece of software in extras-devel repository called ‘catblock’ – call and text blocker for maemo / n900. Actually in early development stage, but it works :)

  22. I got 2 problems, maybe some1 will be kind enough to respond and helps us out
    1. Where is actually situated MyDocs
    2. On qwerty keyboard isn`t any “&”, how can we get it?
      
    All the best

Leave us a Comment