Bug 882551 - Patch 5: Change return type of internal functions, r=qdot, r=mrbkap, r=echou

This commit is contained in:
Gina Yeh 2013-06-20 09:20:16 +08:00
Родитель 20f995abc1
Коммит d4801377c8
8 изменённых файлов: 79 добавлений и 100 удалений

Просмотреть файл

@ -36,7 +36,8 @@ BluetoothA2dpManager::Observe(nsISupports* aSubject,
MOZ_ASSERT(gBluetoothA2dpManager);
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
return HandleShutdown();
HandleShutdown();
return NS_OK;
}
MOZ_ASSERT(false, "BluetoothA2dpManager got unexpected topic!");
@ -119,14 +120,13 @@ BluetoothA2dpManager::Get()
return gBluetoothA2dpManager;
}
nsresult
void
BluetoothA2dpManager::HandleShutdown()
{
MOZ_ASSERT(NS_IsMainThread());
gInShutdown = true;
Disconnect();
gBluetoothA2dpManager = nullptr;
return NS_OK;
}
bool
@ -241,7 +241,7 @@ BluetoothA2dpManager::NotifyStatusChanged()
{
MOZ_ASSERT(NS_IsMainThread());
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_A2DP_STATUS_CHANGED);
NS_NAMED_LITERAL_STRING(type, BLUETOOTH_A2DP_STATUS_CHANGED_ID);
InfallibleTArray<BluetoothNamedValue> parameters;
BluetoothValue v = mConnected;
@ -271,7 +271,7 @@ BluetoothA2dpManager::NotifyAudioManager()
data.AppendInt(mConnected);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_A2DP_STATUS_CHANGED,
BLUETOOTH_A2DP_STATUS_CHANGED_ID,
data.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-a2dp-status-changed observsers!");
}

Просмотреть файл

@ -35,8 +35,6 @@ public:
bool Connect(const nsAString& aDeviceAddress);
void Disconnect();
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
nsresult HandleShutdown();
virtual void OnGetServiceChannel(const nsAString& aDeviceAddress,
const nsAString& aServiceUuid,
@ -44,12 +42,15 @@ public:
virtual void OnUpdateSdpRecords(const nsAString& aDeviceAddress) MOZ_OVERRIDE;
virtual void GetAddress(nsAString& aDeviceAddress) MOZ_OVERRIDE;
void HandleSinkPropertyChanged(const BluetoothSignal& aSignal);
private:
BluetoothA2dpManager();
bool Init();
void Cleanup();
void HandleSinkStateChanged(SinkState aState);
void HandleShutdown();
void NotifyStatusChanged();
void NotifyAudioManager();

Просмотреть файл

@ -55,8 +55,8 @@ extern bool gBluetoothDebugFlag;
* When connection status of Bluetooth profiles change, we'll notify observers
* of following topics.
*/
#define BLUETOOTH_SCO_STATUS_CHANGED "bluetooth-sco-status-changed"
#define BLUETOOTH_A2DP_STATUS_CHANGED "bluetooth-a2dp-status-changed"
#define BLUETOOTH_SCO_STATUS_CHANGED_ID "bluetooth-sco-status-changed"
#define BLUETOOTH_A2DP_STATUS_CHANGED_ID "bluetooth-a2dp-status-changed"
// Bluetooth address format: xx:xx:xx:xx:xx:xx (or xx_xx_xx_xx_xx_xx)
#define BLUETOOTH_ADDRESS_LENGTH 17

Просмотреть файл

@ -26,11 +26,6 @@
#include "nsITelephonyProvider.h"
#include "nsRadioInterfaceLayer.h"
#define AUDIO_VOLUME_BT_SCO "audio.volume.bt_sco"
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define MOBILE_CONNECTION_ICCINFO_CHANGED "mobile-connection-iccinfo-changed"
#define MOBILE_CONNECTION_VOICE_CHANGED "mobile-connection-voice-changed"
/**
* BRSF bitmask of AG supported features. See 4.34.1 "Bluetooth Defined AT
* Capabilities" in Bluetooth hands-free profile 1.6
@ -56,6 +51,11 @@
#define CR_LF "\xd\xa";
#define MOZSETTINGS_CHANGED_ID "mozsettings-changed"
#define MOBILE_CONNECTION_ICCINFO_CHANGED_ID "mobile-connection-iccinfo-changed"
#define MOBILE_CONNECTION_VOICE_CHANGED_ID "mobile-connection-voice-changed"
#define AUDIO_VOLUME_BT_SCO_ID "audio.volume.bt_sco"
using namespace mozilla;
using namespace mozilla::ipc;
USING_BLUETOOTH_NAMESPACE
@ -165,7 +165,7 @@ public:
NS_ENSURE_TRUE(cx, NS_OK);
if (!aResult.isNumber()) {
NS_WARNING("'" AUDIO_VOLUME_BT_SCO "' is not a number!");
NS_WARNING("'" AUDIO_VOLUME_BT_SCO_ID "' is not a number!");
return NS_OK;
}
@ -178,7 +178,7 @@ public:
NS_IMETHOD
HandleError(const nsAString& aName)
{
NS_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO "'");
NS_WARNING("Unable to get value for '" AUDIO_VOLUME_BT_SCO_ID "'");
return NS_OK;
}
};
@ -192,17 +192,19 @@ BluetoothHfpManager::Observe(nsISupports* aSubject,
const PRUnichar* aData)
{
if (!strcmp(aTopic, MOZSETTINGS_CHANGED_ID)) {
return HandleVolumeChanged(nsDependentString(aData));
HandleVolumeChanged(nsDependentString(aData));
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
return HandleShutdown();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_ICCINFO_CHANGED)) {
return HandleIccInfoChanged();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_VOICE_CHANGED)) {
return HandleVoiceConnectionChanged();
HandleShutdown();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_ICCINFO_CHANGED_ID)) {
HandleIccInfoChanged();
} else if (!strcmp(aTopic, MOBILE_CONNECTION_VOICE_CHANGED_ID)) {
HandleVoiceConnectionChanged();
} else {
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
return NS_ERROR_UNEXPECTED;
}
MOZ_ASSERT(false, "BluetoothHfpManager got unexpected topic!");
return NS_ERROR_UNEXPECTED;
return NS_OK;
}
void
@ -373,7 +375,7 @@ BluetoothHfpManager::Init()
NS_ENSURE_SUCCESS(rv, false);
nsRefPtr<GetVolumeTask> callback = new GetVolumeTask();
rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO, callback);
rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO_ID, callback);
NS_ENSURE_SUCCESS(rv, false);
Listen();
@ -492,13 +494,13 @@ BluetoothHfpManager::NotifyAudioManager(bool aStatus)
data.AppendInt(aStatus);
if (NS_FAILED(obs->NotifyObservers(this,
BLUETOOTH_SCO_STATUS_CHANGED,
BLUETOOTH_SCO_STATUS_CHANGED_ID,
data.BeginReading()))) {
NS_WARNING("Failed to notify bluetooth-sco-status-changed observsers!");
}
}
nsresult
void
BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
{
MOZ_ASSERT(NS_IsMainThread());
@ -508,50 +510,28 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
// {"key":"volumedown", "value":2}
JSContext* cx = nsContentUtils::GetSafeJSContext();
if (!cx) {
NS_WARNING("Failed to get JSContext");
return NS_OK;
}
NS_ENSURE_TRUE_VOID(cx);
JS::Rooted<JS::Value> val(cx);
if (!JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val)) {
return JS_ReportPendingException(cx) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE_VOID(JS_ParseJSON(cx, aData.BeginReading(), aData.Length(), &val));
NS_ENSURE_TRUE_VOID(val.isObject());
if (!val.isObject()) {
return NS_OK;
}
JSObject& obj(val.toObject());
JS::Value key;
if (!JS_GetProperty(cx, &obj, "key", &key)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!key.isString()) {
return NS_OK;
JS::Rooted<JSObject*> obj(cx, &val.toObject());
JS::Rooted<JS::Value> key(cx);
if (!JS_GetProperty(cx, obj, "key", key.address()) || !key.isString()) {
return;
}
JSBool match;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO, &match)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
if (!JS_StringEqualsAscii(cx, key.toString(), AUDIO_VOLUME_BT_SCO_ID, &match) ||
(match != JS_TRUE)) {
return;
}
if (!match) {
return NS_OK;
}
JS::Value value;
if (!JS_GetProperty(cx, &obj, "value", &value)) {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
return NS_ERROR_OUT_OF_MEMORY;
}
if (!value.isNumber()) {
return NS_ERROR_UNEXPECTED;
JS::Rooted<JS::Value> value(cx);
if (!JS_GetProperty(cx, obj, "value", value.address())||
!value.isNumber()) {
return;
}
mCurrentVgs = value.toNumber();
@ -559,27 +539,25 @@ BluetoothHfpManager::HandleVolumeChanged(const nsAString& aData)
// Adjust volume by headset and we don't have to send volume back to headset
if (mReceiveVgsFlag) {
mReceiveVgsFlag = false;
return NS_OK;
return;
}
// Only send volume back when there's a connected headset
if (IsConnected()) {
SendCommand("+VGS: ", mCurrentVgs);
}
return NS_OK;
}
nsresult
void
BluetoothHfpManager::HandleVoiceConnectionChanged()
{
nsCOMPtr<nsIMobileConnectionProvider> connection =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(connection, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(connection);
nsIDOMMozMobileConnectionInfo* voiceInfo;
connection->GetVoiceConnectionInfo(&voiceInfo);
NS_ENSURE_TRUE(voiceInfo, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(voiceInfo);
bool roaming;
voiceInfo->GetRoaming(&roaming);
@ -598,7 +576,7 @@ BluetoothHfpManager::HandleVoiceConnectionChanged()
voiceInfo->GetRelSignalStrength(&value);
if (!value.isNumber()) {
NS_WARNING("Failed to get relSignalStrength in BluetoothHfpManager");
return NS_ERROR_FAILURE;
return;
}
signal = ceil(value.toNumber() / 20.0);
UpdateCIND(CINDType::SIGNAL, signal);
@ -619,7 +597,7 @@ BluetoothHfpManager::HandleVoiceConnectionChanged()
nsIDOMMozMobileNetworkInfo* network;
voiceInfo->GetNetwork(&network);
NS_ENSURE_TRUE(network, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(network);
network->GetLongName(mOperatorName);
// According to GSM 07.07, "<format> indicates if the format is alphanumeric
@ -634,26 +612,22 @@ BluetoothHfpManager::HandleVoiceConnectionChanged()
NS_WARNING("The operator name was longer than 16 characters. We cut it.");
mOperatorName.Left(mOperatorName, 16);
}
return NS_OK;
}
nsresult
void
BluetoothHfpManager::HandleIccInfoChanged()
{
nsCOMPtr<nsIMobileConnectionProvider> connection =
do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
NS_ENSURE_TRUE(connection, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(connection);
nsIDOMMozMobileICCInfo* iccInfo;
connection->GetIccInfo(&iccInfo);
NS_ENSURE_TRUE(iccInfo, NS_ERROR_FAILURE);
NS_ENSURE_TRUE_VOID(iccInfo);
iccInfo->GetMsisdn(mMsisdn);
return NS_OK;
}
nsresult
void
BluetoothHfpManager::HandleShutdown()
{
MOZ_ASSERT(NS_IsMainThread());
@ -661,7 +635,6 @@ BluetoothHfpManager::HandleShutdown()
Disconnect();
DisconnectSco();
gBluetoothHfpManager = nullptr;
return NS_OK;
}
// Virtual function of class SocketConsumer

Просмотреть файл

@ -103,10 +103,10 @@ private:
friend class BluetoothHfpManagerObserver;
BluetoothHfpManager();
nsresult HandleIccInfoChanged();
nsresult HandleShutdown();
nsresult HandleVolumeChanged(const nsAString& aData);
nsresult HandleVoiceConnectionChanged();
void HandleIccInfoChanged();
void HandleShutdown();
void HandleVolumeChanged(const nsAString& aData);
void HandleVoiceConnectionChanged();
bool Init();
void Notify(const hal::BatteryInformation& aBatteryInfo);

Просмотреть файл

@ -73,7 +73,8 @@ BluetoothOppManager::Observe(nsISupports* aSubject,
MOZ_ASSERT(sInstance);
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
return HandleShutdown();
HandleShutdown();
return NS_OK;
}
MOZ_ASSERT(false, "BluetoothOppManager got unexpected topic!");
@ -226,6 +227,7 @@ BluetoothOppManager::Get()
if (!sInstance) {
sInstance = new BluetoothOppManager();
NS_ENSURE_TRUE(sInstance->Init(), nullptr);
}
return sInstance;
@ -288,14 +290,13 @@ BluetoothOppManager::Disconnect()
}
}
nsresult
void
BluetoothOppManager::HandleShutdown()
{
MOZ_ASSERT(NS_IsMainThread());
sInShutdown = true;
Disconnect();
sInstance = nullptr;
return NS_OK;
}
bool

Просмотреть файл

@ -96,7 +96,7 @@ public:
private:
BluetoothOppManager();
bool Init();
nsresult HandleShutdown();
void HandleShutdown();
void StartFileTransfer();
void StartSendingNextFile();

Просмотреть файл

@ -194,8 +194,8 @@ AudioManager::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
if ((strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED) == 0) ||
(strcmp(aTopic, BLUETOOTH_A2DP_STATUS_CHANGED) == 0)) {
if ((strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED_ID) == 0) ||
(strcmp(aTopic, BLUETOOTH_A2DP_STATUS_CHANGED_ID) == 0)) {
nsresult rv;
int status = NS_ConvertUTF16toUTF8(aData).ToInteger(&rv);
if (NS_FAILED(rv) || status > 1 || status < 0) {
@ -213,7 +213,7 @@ AudioManager::Observe(nsISupports* aSubject,
AUDIO_POLICY_DEVICE_STATE_AVAILABLE :
AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
if (!strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED)) {
if (!strcmp(aTopic, BLUETOOTH_SCO_STATUS_CHANGED_ID)) {
AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET,
audioState, address.get());
AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
@ -230,7 +230,7 @@ AudioManager::Observe(nsISupports* aSubject,
if (force == nsIAudioManager::FORCE_BT_SCO)
SetForceForUse(nsIAudioManager::USE_COMMUNICATION, nsIAudioManager::FORCE_NONE);
}
} else if (!strcmp(aTopic, BLUETOOTH_A2DP_STATUS_CHANGED)) {
} else if (!strcmp(aTopic, BLUETOOTH_A2DP_STATUS_CHANGED_ID)) {
AudioSystem::setDeviceConnectionState(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP,
audioState, address.get());
if (audioState == AUDIO_POLICY_DEVICE_STATE_AVAILABLE) {
@ -283,10 +283,12 @@ AudioManager::AudioManager() : mPhoneState(PHONE_STATE_CURRENT),
NotifyHeadphonesStatus(GetCurrentSwitchState(SWITCH_HEADPHONES));
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (NS_FAILED(obs->AddObserver(this, BLUETOOTH_SCO_STATUS_CHANGED, false))) {
NS_WARNING("Failed to add bluetooth-sco-status-changed oberver!");
} else if (NS_FAILED(obs->AddObserver(this, BLUETOOTH_A2DP_STATUS_CHANGED, false))) {
NS_WARNING("Failed to add bluetooth-a2dp-status-changed oberver!");
NS_ENSURE_TRUE_VOID(obs);
nsresult rv =
obs->AddObserver(this, BLUETOOTH_SCO_STATUS_CHANGED_ID, false) &&
obs->AddObserver(this, BLUETOOTH_A2DP_STATUS_CHANGED_ID, false);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to add bluetooth status changed obervers!");
}
for (int loop = 0; loop < AUDIO_STREAM_CNT; loop++) {
@ -313,10 +315,12 @@ AudioManager::~AudioManager() {
UnregisterSwitchObserver(SWITCH_HEADPHONES, mObserver);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (NS_FAILED(obs->RemoveObserver(this, BLUETOOTH_SCO_STATUS_CHANGED))) {
NS_WARNING("Failed to remove bluetooth-sco-status-changed oberver!");
} else if (NS_FAILED(obs->RemoveObserver(this, BLUETOOTH_A2DP_STATUS_CHANGED))) {
NS_WARNING("Failed to remove bluetooth-a2dp-status-changed oberver!");
NS_ENSURE_TRUE_VOID(obs);
nsresult rv =
obs->RemoveObserver(this, BLUETOOTH_SCO_STATUS_CHANGED_ID) &&
obs->RemoveObserver(this, BLUETOOTH_A2DP_STATUS_CHANGED_ID);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to remove bluetooth status changed obervers!");
}
}