Reply
Thread Tools
Posts: 11 | Thanked: 3 times | Joined on Dec 2009
#1
Anybody has an idea how to activate bluetooth automatically when calls are incoming. I would like to have bluetooth only activated during calls to work with headset. This is for security and battery power reasons.
How can I do this? Is there an event triggered in the system, so I can write a simple activation script?

I am quite new to this device hacking, so sorry for a probably dummy question. A simple pointer would be helpful as well of course. ;-)

Have a nice day
Thomas
 

The Following User Says Thank You to thhart For This Useful Post:
JonWW's Avatar
Posts: 623 | Thanked: 289 times | Joined on Jan 2010 @ UK
#2
To switch bluetooth on
Code:
dbus-send --system --type=method_call --dest=org.bluez $(dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | awk -F'"' '/at/ {print $2}') org.bluez.Adapter.SetProperty string:Powered variant:boolean:true
To switch bluetooth off
Code:
dbus-send --system --type=method_call --dest=org.bluez $(dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | awk -F'"' '/at/ {print $2}') org.bluez.Adapter.SetProperty string:Powered variant:boolean:false
Use dbus-monitor to monitor the system and trigger an event when you get/make a call
Code:
dbus-monitor --help
For example this will catch when the keyboard is opened or closed.
Code:
dbus-monitor --monitor --system type='signal',interface='org.freedesktop.Hal.Device',path='/org/freedesktop/Hal/devices/platform_slide',member='Condition'|while read LINE
  do
    echo "$LINE"|grep -o "cover"
  done
The only problem is will the bluetooth connect to your headset in time before the caller hangs up.
 

The Following 4 Users Say Thank You to JonWW For This Useful Post:
Posts: 11 | Thanked: 3 times | Joined on Dec 2009
#3
Originally Posted by JonWW View Post
The only problem is will the bluetooth connect to your headset in time before the caller hangs up.
The pairing is quite fast and I have found out I have enough time to turn on the headset and get it ready within 10 seconds.

Thanks for you suggestion - will test it soon...

Thomas
 
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#4
Here is also dbus-script event that will switch on/off bluetooth during call:

Code:
asN900:~# cat /etc/dbus-scripts.d/bluetooth-during-call 
/home/user/bin/bton.sh * * com.nokia.policy.telephony call_request
/home/user/bin/btoff.sh * * com.nokia.policy.telephony call_ended
Where bton.sh and btoff.sh are the examples posted by JonWW
 

The Following User Says Thank You to lidow For This Useful Post:
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#5
I wanted to have this:

* bluetooth to be on only during a call
* when switch on, force connect to my BT handsfree if available
* when call is over, switch off bluetooth only if bluetooth is not started manually

These are the scripts to achieve it:

/etc/dbus-scripts.d/bluetooth-during-call
Code:
/home/user/bin/bton.sh * * com.nokia.policy.telephony call_request
/home/user/bin/btoff.sh * * com.nokia.policy.telephony call_ended
/home/user/bin/bton.sh
Code:
#!/bin/sh

adapter=$(dbus-send --print-reply --system --dest=org.bluez / org.bluez.Manager.DefaultAdapter| sed -ne "s/^.*object path //p"|sed -e 's/"//g')

if ( dbus-send --system --print-reply --type=method_call --dest=org.bluez ${adapter} org.bluez.Adapter.GetProperties | sed -n '/string "Powered"/,/variant/ p' | grep -q false )
then
        dbus-send --system --type=method_call --dest=org.bluez $adapter org.bluez.Adapter.SetProperty string:Powered variant:boolean:true
        touch /tmp/bt.autopowered
fi


devmac=00:1C:EF:75:D4:B5

device=$(dbus-send --print-reply --system --dest=org.bluez ${adapter} org.bluez.Adapter.FindDevice string:${devmac}|sed -ne "s/^.*object path //p"|sed -e 's/"//g')
dbus-send --system --print-reply --type=method_call --dest=org.bluez ${device} org.bluez.Audio.Connect
!!!NOTE: change devmac to proper value for your BT handsfree

/home/user/bin/btoff.sh
Code:
#!/bin/sh

if [[ -f /tmp/bt.autopowered ]]
then
        dbus-send --system --type=method_call --dest=org.bluez $(dbus-send --system --print-reply --dest=org.bluez / org.bluez.Manager.ListAdapters | awk -F'"' '/at/ {print $2}') org.bluez.Adapter.SetProperty string:Powered variant:boolean:false
        rm /tmp/bt.autopowered
fi

TODO:

* disable WLAN during calls, as there are sound distortions while both BT and WLAN are enabled. Do not happen always, but I could not determine the pattern when/what is causing it.
 

The Following 4 Users Say Thank You to lidow For This Useful Post:
dr_frost_dk's Avatar
Posts: 1,503 | Thanked: 2,688 times | Joined on Oct 2010 @ Denmark
#6
Originally Posted by lidow View Post
I think this should help.

change in file /etc/bluetooth/audio.conf

from:
HFP=true

to:
HFP=false

restart the phone
Originally Posted by lidow View Post
Hmmm, just notice that this is for hfp/hsp. While you want it for a2dp.
Try, but most likely will not help. Anyway it is not so hard to disconect BT during call.
no it is not hard to disconnect, but lets say that the phone is 10secs away, now the remaining time left to answer is shorter....

And lets continue in your thread, you where first
 
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#7
what means 10secs away.
it disconnects almost immediatly.

infact this is not my thread, it is started by thhart.

Last edited by lidow; 2011-08-25 at 19:18.
 
Posts: 48 | Thanked: 22 times | Joined on Jan 2008
#8
@dr_frost_dk

I am not sure the answer to your issue, but I can provide one datapoint. When my n900 is connected to the Sony bluetooth headunit in my car it switches automatically between playing audio with A2DP/AVRCP to HSP/HFP at the start and end of a call. I have not modified n900 stock settings in this regard, so perhaps keeping a BT headset around may be a crude solution.
 
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#9
you should:

* install dbus-script
* create file
/etc/dbus-scripts.d/no-a2dp-during-call
Code:
/home/user/bin/a2dpoff.sh * * com.nokia.policy.telephony call_request
/home/user/bin/a2dpon.sh * * com.nokia.policy.telephony call_ended
* create both scripts

/home/user/bin/a2dpoff.sh
Code:
#!/bin/sh

adapter=$(dbus-send --print-reply --system --dest=org.bluez / org.bluez.Manager.DefaultAdapter| sed -ne "s/^.*object path //p"|sed -e 's/"//g')

devmac=00:1C:EF:75:D4:B5

device=$(dbus-send --print-reply --system --dest=org.bluez ${adapter} org.bluez.Adapter.FindDevice string:${devmac}|sed -ne "s/^.*object path //p"|sed -e 's/"//g')
dbus-send --system --print-reply --type=method_call --dest=org.bluez ${device} org.bluez.Audio.Disconnect
/home/user/bin/a2dpon.sh
Code:
#!/bin/sh

adapter=$(dbus-send --print-reply --system --dest=org.bluez / org.bluez.Manager.DefaultAdapter| sed -ne "s/^.*object path //p"|sed -e 's/"//g')

devmac=00:1C:EF:75:D4:B5

device=$(dbus-send --print-reply --system --dest=org.bluez ${adapter} org.bluez.Adapter.FindDevice string:${devmac}|sed -ne "s/^.*object path //p"|sed -e 's/"//g')
dbus-send --system --print-reply --type=method_call --dest=org.bluez ${device} org.bluez.Audio.Connect
 

The Following User Says Thank You to lidow For This Useful Post:
Posts: 151 | Thanked: 93 times | Joined on Sep 2009 @ sofia, bulgaria
#10
Originally Posted by ashes View Post
@dr_frost_dk

I am not sure the answer to your issue, but I can provide one datapoint. When my n900 is connected to the Sony bluetooth headunit in my car it switches automatically between playing audio with A2DP/AVRCP to HSP/HFP at the start and end of a call. I have not modified n900 stock settings in this regard, so perhaps keeping a BT headset around may be a crude solution.
So try with the setting before the script...
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 10:38.