• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
UBports Robot Logo UBports Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

[HowTo] Block unwanted calls - create blacklist

Scheduled Pinned Locked Moved Support
21 Posts 6 Posters 4.8k Views 7 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      Br1
      last edited by 18 Jul 2022, 23:04

      --------- update ---------

      To fix security issue mentioned by @klh, I have created an init.d service.

      • Create a new contact and call it SPAM, add to it the numbers you want to block

      • First script
        nano /home/phablet/.myscripts/calls_blocker.sh
        and make it executable (chmod u+x)

      #!/bin/bash
      
      # Intercepts every incoming call addressed to SPAM contact and terminates it
      
      interface=org.freedesktop.DBus.Properties
      member=Set
      
      dbus-monitor --system interface=$interface member=$member | awk '/SPAM/ {
          system("dbus-send --system --print-reply --dest=org.ofono /ril_0/voicecall01 org.ofono.VoiceCall.Hangup") 1>/dev/null
        }'
      
      • Second script
        nano /home/phablet/.myscripts/stop_blocker.sh
        (chmod u+x)
      #!/bin/bash
      
      # stop process gracefully
      
      pkill dbus-monitor
      
      exit
      
      • mount system in rw mode
      sudo mount -o remount,rw /
      
      • create service
        sudo nano /etc/init.d/blacklist
        and set permissions (sudo chmod 755)
      #! /bin/bash
      
      ### BEGIN INIT INFO
      # Provides:          blacklist
      # Required-Start:    dbus
      # Required-Stop:     dbus
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: Blocks calls
      # Description:       Daemon that blocks unwanted calls
      ### END INIT INFO
      
      # Written by Br1 <br1@spacelinux.it>
      
      case "$1" in
        start)
          echo "Starting blacklist service ..."
          bash -c 'cd /home/phablet/.aa_myscripts/ && ./calls_blocker.sh &'
          ;;
        stop)
          echo "Stopping blacklist service ..."
          bash -c 'cd /home/phablet/.aa_myscripts/ && ./stop_blocker.sh &'
          sleep 2
          ;;
        *)
          echo "Usage: /etc/init.d/blacklist {start|stop}"
          exit 1
          ;;
      esac
      
      exit 0
      
      
      • start or stop service with
      sudo service blacklist start 
      # or
      sudo service blacklist stop
      
      • enable service auto start on boot up
      sudo update-rc.d blacklist defaults
      
      • if you want disable service auto start on boot up
      sudo update-rc.d -f blacklist remove
      
      • check if service/dbus-monitor is running
      ps -e | grep dbus-monitor
      

      ^

      • Google Pixel 3a XL
      • Xiaomi MI A2
      _ 1 Reply Last reply 27 Jan 2023, 20:24 Reply Quote 5
      • K Keneda referenced this topic on 28 Jul 2022, 04:06
      • K Keneda referenced this topic on 28 Jul 2022, 04:17
      • K Keneda referenced this topic on 28 Jul 2022, 04:25
      • K Keneda referenced this topic on 28 Jul 2022, 04:31
      • K Keneda referenced this topic on 28 Jul 2022, 04:36
      • _ Offline
        _Joao_ @Br1
        last edited by 27 Jan 2023, 20:24

        @br1 Thanks it works perfectly

        1 Reply Last reply Reply Quote 0
        • _ Offline
          _Joao_
          last edited by 4 Feb 2023, 18:08

          The problem is the battery consumption, it lasts 2 hours with the scripts activated on my nexus.

          E 1 Reply Last reply 6 Feb 2023, 07:06 Reply Quote 0
          • E Offline
            Emphrath @_Joao_
            last edited by 6 Feb 2023, 07:06

            @joao-0 u sure it's the script ? Nexus has catastrophic battery life

            _ 1 Reply Last reply 9 Feb 2023, 20:25 Reply Quote 0
            • _ Offline
              _Joao_ @Emphrath
              last edited by 9 Feb 2023, 20:25

              @emphrath yes I am sure

              1 Reply Last reply Reply Quote 0
              • B Br1 referenced this topic on 12 Feb 2023, 14:25
              • B Offline
                Br1
                last edited by 20 Feb 2023, 23:21

                --------- UPDATE ---------
                New version to install/uninstall with single command, see here for further information.

                The old version has to be manually uninstalled before.

                There are no new features but should be running much faster and draw less battery power (*)

                three steps :

                1 - download (just click) blacklist.1.01.tar.gz from here

                2 - open file manager, go to Downloads click blacklist.1.01.tar.gz and extract archive

                3 - open terminal and type :

                sudo /home/phablet/Downloads/blacklist.1.01/blist-install
                

                type 1 to install
                type 2 to uninstall
                type 3 to exit

                That's all.

                Preview of install/uninstall script (blist-install) :

                #!/bin/bash
                
                BLSERV=/etc/init.d/blacklist ;
                
                # Make sure only root can run this script
                if [ "$(id -u)" != "0" ]; then
                   echo "    Must be run as root, you must prepend sudo !" 1>&2 ; exit 1
                fi
                
                echo -e '\n - Install/uninstall BlackList :\n' ;
                
                PS3='Please enter your choice : '
                options=("Install" "Uninstall" "Quit")
                select opt in "${options[@]}"
                do
                	case $opt in
                	"Install")
                
                 			echo -e '\n Installation in progress ...\n' ;
                
                			# change the working directory
                			cd /home/phablet/Downloads/blacklist.1.01/ ;
                			
                			# create directory
                			mkdir -p /home/phablet/.blacklist ;
                
                			# copy scripts to directory just created 			
                			cp *.sh /home/phablet/.blacklist/ ;
                			
                			# mount root in read/write mode
                			mount -o remount,rw / ;
                			
                			# copy blacklist service
                			cp blacklist /etc/init.d/ ;
                			
                			# enable autostart
                			update-rc.d blacklist defaults ;
                			
                			# start service
                			service blacklist start
                			
                			# roll back root in read only mode
                			mount -o remount,ro / ;
                
                			echo -e '\n Done, Blacklist installed !\n'
                			
                			exit 0
                
                		;;
                
                	"Uninstall")
                
                			# check status
                			if [ ! -f "$BLSERV" ]; then
                
                			echo -e '\n Blacklist is not installed !\n' ;
                
                			else
                
                			# mount root in read/write mode
                			mount -o remount,rw / ;
                
                			# stop blacklist service, disable autostart and remove file
                			service blacklist stop ; update-rc.d -f blacklist remove ; rm /etc/init.d/blacklist ;
                
                			# roll back root in read only mode
                			mount -o remount,ro / ;
                
                			# delete scripts and remove directory
                			rm -rf /home/phablet/.blacklist/* ; rmdir /home/phablet/.blacklist ;
                
                			echo -e '\n Blacklist uninstalled !\n'
                
                			exit 0
                
                			fi
                
                		;;
                
                        "Quit")
                			exit 0
                		;;
                			*) echo "invalid option $REPLY"
                		;;
                    esac
                done
                
                
                • small changes to make more efficient the script (now named sr-kill.sh) useful to stop blacklist service from command line :
                #!/bin/sh
                
                # stop blacklist service
                
                # get pid of the script
                scPID=$(pidof -x calls_blocker.sh)
                
                # kill script and child processes
                pkill -P $scPID
                
                exit
                
                

                (*) Now the always running script (calls_blocker.sh) is executed by dash shell which is much faster and requires fewer resources than bash shell, see benchmark , here is the preview :

                #!/bin/sh
                
                # Intercepts every incoming call addressed to SPAM contact and terminates it
                
                interface=org.freedesktop.DBus.Properties
                member=Set
                
                sudo dbus-monitor --system interface=$interface member=$member | awk '/SPAM/ {
                   system("dbus-send --system --print-reply --dest=org.ofono /ril_0/voicecall01 org.ofono.VoiceCall.Hangup") }' >/dev/null 2>&1
                
                

                ^

                • Google Pixel 3a XL
                • Xiaomi MI A2
                _ 2 Replies Last reply 4 Mar 2023, 13:24 Reply Quote 2
                • _ Offline
                  _Joao_
                  last edited by 26 Feb 2023, 10:47

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • _ Offline
                    _Joao_ @Br1
                    last edited by 4 Mar 2023, 13:24

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • _ Offline
                      _Joao_ @Br1
                      last edited by 4 Mar 2023, 19:19

                      Hello the program works perfectly. The autonomy is frankly superior to the old version, the application consumes 9% per hour on my nexus 5 with a new battery. Without the appication my nexus 5 consumes 3% per hour. It's a bit fair but as you say the nexus has a limited basic autonomy.
                      Thanks, great job.

                      1 Reply Last reply Reply Quote 0
                      • B Offline
                        Br1
                        last edited by 4 Apr 2023, 18:47

                        OTA-25 --- You can reinstall, no changes are necessary.

                        ^

                        • Google Pixel 3a XL
                        • Xiaomi MI A2
                        1 Reply Last reply Reply Quote 1
                        • B Offline
                          Br1
                          last edited by 13 Sept 2023, 14:56

                          ---- UPDATE OTA-2 Focal ----
                          ---- Stable Channel ----

                          Usual three steps :

                          1 - download (just tap) blacklist-ota.2 from here

                          2 - open file manager, go to Downloads tap blacklist-ota.2.tar.gz and tap extract archive

                          3 - open terminal, type :

                          sudo Downloads/blacklist-ota.2/blist-install
                          

                          and hit enter,

                          type 1 + enter to install

                          type 2 + enter to uninstall

                          reboot not required.


                          Blacklist only consist of three files :

                          preview of blist-install :

                          #!/bin/bash
                          
                          BLSERV=/usr/lib/systemd/system/blacklist.service ;
                          
                          # Make sure only root can run this script
                          if [ "$(id -u)" != "0" ]; then
                             echo "    Must be run as root, you must prepend sudo !" 1>&2 ; exit 1
                          fi
                          
                          echo -e '\n  -  Install-Uninstall BlackList :\n' ;
                          
                          PS3=$'
                          Please enter your choice : '
                          options=("  Install    -       " "  Uninstall  -       " "  Quit       -       ")
                          
                          select opt in "${options[@]}"
                          do
                          	case $opt in
                          	"  Install    -       ")
                          
                           			echo -e '\n Installation in progress ...\n' ;
                          
                          			# change the working directory
                          			cd /home/phablet/Downloads/blacklist-ota.2/ ;
                          
                          			# create directory
                          			mkdir -p /home/phablet/.blacklist ;
                          
                          			# copy scripts to directory just created
                          			cp calls_blocker.sh /home/phablet/.blacklist/ ;
                          
                          			# mount root in read/write mode
                          			mount -o remount,rw / ;
                          
                          			# copy blacklist service
                          			cp blacklist.service /usr/lib/systemd/system/ ;
                          
                          			# enable and start service
                          			systemctl enable --now blacklist > /dev/null 2>&1 ;
                          
                          			# roll back root in read only mode
                          			mount -o remount,ro / ;
                          
                          			echo -e '\n Done, Blacklist installed !\n'
                          
                          			exit 0
                          
                          		;;
                          
                          	"  Uninstall  -       ")
                          
                          			# check status
                          			if [ ! -f "$BLSERV" ]; then
                          
                          			echo -e '\n Blacklist is not installed !\n' ;
                          
                          			else
                          
                          			# mount root in read/write mode
                          			mount -o remount,rw / ;
                          
                          			# stop and disable blacklist service
                          			systemctl disable --now blacklist > /dev/null 2>&1 ;
                          
                          			# remove file
                          			rm /usr/lib/systemd/system/blacklist.service ;
                          
                          			# roll back root in read only mode
                          			mount -o remount,ro / ;
                          
                          			# delete scripts and remove directory
                          			rm -rf /home/phablet/.blacklist/* ; rmdir /home/phablet/.blacklist ;
                          
                          			echo -e '\n Blacklist uninstalled !\n'
                          
                          			exit 0
                          
                          			fi
                          
                          		;;
                          
                                  "  Quit       -       ")
                          			echo -e '\n - OS unchanged !\n'
                          
                          			exit 0
                          		;;
                          			*) echo "invalid option $REPLY"
                          		;;
                              esac
                          done
                          

                          preview of blacklist.service :

                          [Unit]
                          Description=Calls Blacklist
                          
                          [Service]
                          Type=simple
                          ExecStart=/home/phablet/.blacklist/calls_blocker.sh
                          RemainAfterExit=yes
                          
                          [Install]
                          WantedBy=multi-user.target
                          
                          

                          calls_blocker.sh script has not changed.

                          The script to stop service is no longer necessary, blacklist now is a systemd service and can be managed with systemctl commands, example :

                          systemctl stop blacklist
                          

                          improved legibility :
                          screenshot20230912.png

                          ^

                          • Google Pixel 3a XL
                          • Xiaomi MI A2
                          1 Reply Last reply Reply Quote 2
                          • B Offline
                            Br1
                            last edited by Br1 14 Nov 2023, 12:38

                            I can’t test ota 3 update, install at your own risk.

                            ^

                            • Google Pixel 3a XL
                            • Xiaomi MI A2
                            1 Reply Last reply Reply Quote 0
                            • B Offline
                              Br1
                              last edited by 15 Nov 2023, 13:05

                              OTA 3 Stable channel --- You can reinstall, no changes are necessary.

                              ^

                              • Google Pixel 3a XL
                              • Xiaomi MI A2
                              1 Reply Last reply Reply Quote 0
                              • B Offline
                                Br1
                                last edited by 11 Feb 2024, 18:52

                                Blacklist also work fine with OTA 4.

                                ^

                                • Google Pixel 3a XL
                                • Xiaomi MI A2
                                1 Reply Last reply Reply Quote 1
                                • B Br1 referenced this topic on 27 Aug 2024, 15:17
                                • First post
                                  Last post