Bug 792002 - patch 2: adjust volume after receiving AT+VGS, r=qdot, r=fabrice

This commit is contained in:
Eric Chou 2012-09-27 10:24:39 +08:00
parent 374afd78e6
commit 5e04074c7f
3 changed files with 41 additions and 1 deletions

View File

@ -440,6 +440,16 @@ Services.obs.addObserver(function onWebappsReady(subject, topic, data) {
shell.sendChromeEvent({ type: 'webapps-registry-ready' });
}, 'webapps-registry-ready', false);
Services.obs.addObserver(function onBluetoothVolumeChange(subject, topic, data) {
if (data == 'up') {
shell.sendChromeEvent({ type: 'volume-up-button-press' });
shell.sendChromeEvent({ type: 'volume-up-button-release' });
} else if (data == 'down') {
shell.sendChromeEvent({ type: 'volume-down-button-press' });
shell.sendChromeEvent({ type: 'volume-down-button-release' });
}
}, 'bluetooth-volume-change', false);
(function Repl() {
if (!Services.prefs.getBoolPref('b2g.remote-js.enabled')) {
return;

View File

@ -10,12 +10,15 @@
#include "BluetoothService.h"
#include "BluetoothServiceUuid.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
USING_BLUETOOTH_NAMESPACE
using namespace mozilla::ipc;
static nsRefPtr<BluetoothHfpManager> sInstance = nullptr;
BluetoothHfpManager::BluetoothHfpManager()
BluetoothHfpManager::BluetoothHfpManager() : mCurrentVgs(-1)
{
}
@ -79,6 +82,31 @@ BluetoothHfpManager::ReceiveSocketData(UnixSocketRawData* aMessage)
} else if (!strncmp(msg, "AT+CHLD=", 8)) {
SendLine("OK");
} else if (!strncmp(msg, "AT+VGS=", 7)) {
// VGS range: [0, 15]
int newVgs = msg[7] - '0';
if (strlen(msg) > 8) {
newVgs *= 10;
newVgs += (msg[8] - '0');
}
#ifdef DEBUG
NS_ASSERTION(newVgs >= 0 && newVgs <= 15, "Received invalid VGS value");
#endif
// Currently, we send volume up/down commands to represent that
// volume has been changed by Bluetooth headset, and that will affect
// the main stream volume of our device. In the future, we may want to
// be able to set volume by stream.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (newVgs > mCurrentVgs) {
os->NotifyObservers(nullptr, "bluetooth-volume-change", NS_LITERAL_STRING("up").get());
} else if (newVgs < mCurrentVgs) {
os->NotifyObservers(nullptr, "bluetooth-volume-change", NS_LITERAL_STRING("down").get());
}
mCurrentVgs = newVgs;
SendLine("OK");
} else {
#ifdef DEBUG

View File

@ -29,6 +29,8 @@ public:
private:
BluetoothHfpManager();
int mCurrentVgs;
};
END_BLUETOOTH_NAMESPACE