maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   How to activate bluetooth when a call is incoming? (https://talk.maemo.org/showthread.php?t=76035)

thhart 2011-08-24 19:30

How to activate bluetooth when a call is incoming?
 
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

JonWW 2011-08-24 20:08

Re: How to activate bluetooth when a call is incoming?
 
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.

thhart 2011-08-24 22:07

Re: How to activate bluetooth when a call is incoming?
 
Quote:

Originally Posted by JonWW (Post 1075984)
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

lidow 2011-08-25 08:03

Re: How to activate bluetooth when a call is incoming?
 
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

lidow 2011-08-25 14:09

Re: How to activate bluetooth when a call is incoming?
 
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.

dr_frost_dk 2011-08-25 18:59

Re: How to activate bluetooth when a call is incoming?
 
Quote:

Originally Posted by lidow (Post 1076622)
I think this should help.

change in file /etc/bluetooth/audio.conf

from:
HFP=true

to:
HFP=false

restart the phone

Quote:

Originally Posted by lidow (Post 1076626)
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 :D

lidow 2011-08-25 19:05

Re: How to activate bluetooth when a call is incoming?
 
what means 10secs away.
it disconnects almost immediatly.

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

ashes 2011-08-25 19:12

Re: How to activate bluetooth when a call is incoming?
 
@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.

lidow 2011-08-25 19:14

Re: How to activate bluetooth when a call is incoming?
 
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


lidow 2011-08-25 19:17

Re: How to activate bluetooth when a call is incoming?
 
Quote:

Originally Posted by ashes (Post 1076645)
@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...


All times are GMT. The time now is 18:48.

vBulletin® Version 3.8.8