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.
      • Br1B Offline
        Br1 @klh
        last edited by

        @klh

        this is super unsafe as it would allow anyone with access to the device shell (ssh, adb, the terminal app or any unconfined app) to listen in on all dbus traffic

        adb and terminal app require physical access to the device(if someone has your device you already have a bigger problem) ssh with private key is safe, in my opinion the risk is very low ... everyone can evaluate risks and benefits.

        ^

        • Google Pixel 3a XL
        • Xiaomi MI A2
        klhK 1 Reply Last reply Reply Quote 0
        • klhK Offline
          klh @Br1
          last edited by

          @br1 Which is why I posted what the risks are - this is not mentioned in the original post. It's still much safer than paying for an unconfined proprietary app ๐Ÿ™‚

          Also, since you already have to mess with the rootfs and run it as root, you might as well move the upstart job to /etc/init and not mess with the sudoers file.

          1 Reply Last reply Reply Quote 0
          • Br1B Offline
            Br1
            last edited by

            --------- 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 Reply Quote 5
            • KenedaK Keneda referenced this topic on
            • KenedaK Keneda referenced this topic on
            • KenedaK Keneda referenced this topic on
            • KenedaK Keneda referenced this topic on
            • KenedaK Keneda referenced this topic on
            • _ Offline
              _Joao_ @Br1
              last edited by

              @br1 Thanks it works perfectly

              1 Reply Last reply Reply Quote 0
              • _ Offline
                _Joao_
                last edited by

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

                E 1 Reply Last reply Reply Quote 0
                • E Offline
                  Emphrath @_Joao_
                  last edited by

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

                  _ 1 Reply Last reply Reply Quote 0
                  • _ Offline
                    _Joao_ @Emphrath
                    last edited by

                    @emphrath yes I am sure

                    1 Reply Last reply Reply Quote 0
                    • Br1B Br1 referenced this topic on
                    • Br1B Offline
                      Br1
                      last edited by

                      --------- 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 Reply Quote 2
                      • _ Offline
                        _Joao_
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • _ Offline
                          _Joao_ @Br1
                          last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • _ Offline
                            _Joao_ @Br1
                            last edited by

                            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
                            • Br1B Offline
                              Br1
                              last edited by

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

                              ^

                              • Google Pixel 3a XL
                              • Xiaomi MI A2
                              1 Reply Last reply Reply Quote 1
                              • Br1B Offline
                                Br1
                                last edited by

                                ---- 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
                                • Br1B Offline
                                  Br1
                                  last edited by Br1

                                  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
                                  • Br1B Offline
                                    Br1
                                    last edited by

                                    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
                                    • Br1B Offline
                                      Br1
                                      last edited by

                                      Blacklist also work fine with OTA 4.

                                      ^

                                      • Google Pixel 3a XL
                                      • Xiaomi MI A2
                                      1 Reply Last reply Reply Quote 1
                                      • Br1B Br1 referenced this topic on
                                      • First post
                                        Last post