Bug 1161956 - Fix crashes while using GATT client functions. r=jocelyn

This commit is contained in:
Bruce Sun 2015-06-03 18:19:43 +08:00
Родитель fb1b271e1c
Коммит 75cb2ea259
1 изменённых файлов: 41 добавлений и 27 удалений

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

@ -479,7 +479,10 @@ BluetoothGattManager::UnregisterClient(int aClientIf,
size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
ClientIfComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
client->mUnregisterClientRunnable = aRunnable;
@ -580,7 +583,7 @@ BluetoothGattManager::StartLeScan(const nsTArray<nsString>& aServiceUuids,
size_t index = sClients->IndexOf(appUuidStr, 0 /* Start */, UuidComparator());
// Reject the startLeScan request if the clientIf is being used.
if (index != sClients->NoIndex) {
if (NS_WARN_IF(index != sClients->NoIndex)) {
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("start LE scan failed"));
return;
@ -738,7 +741,10 @@ BluetoothGattManager::Disconnect(const nsAString& aAppUuid,
ENSURE_GATT_CLIENT_INTF_IS_READY_VOID(aRunnable);
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
client->mDisconnectRunnable = aRunnable;
@ -782,7 +788,10 @@ BluetoothGattManager::Discover(const nsAString& aAppUuid,
ENSURE_GATT_CLIENT_INTF_IS_READY_VOID(aRunnable);
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
MOZ_ASSERT(client->mConnId > 0);
@ -851,7 +860,10 @@ BluetoothGattManager::ReadRemoteRssi(int aClientIf,
size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
ClientIfComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
client->mReadRemoteRssiRunnable = aRunnable;
@ -915,7 +927,10 @@ BluetoothGattManager::RegisterNotifications(
ENSURE_GATT_CLIENT_INTF_IS_READY_VOID(aRunnable);
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
@ -988,7 +1003,10 @@ BluetoothGattManager::DeregisterNotifications(
ENSURE_GATT_CLIENT_INTF_IS_READY_VOID(aRunnable);
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
MOZ_ASSERT(index != sClients->NoIndex);
if (NS_WARN_IF(index == sClients->NoIndex)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
@ -1049,9 +1067,7 @@ BluetoothGattManager::ReadCharacteristicValue(
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
if (NS_WARN_IF(index == sClients->NoIndex)) {
// Reject the read characteristic value request
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("ReadCharacteristicValue failed"));
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
@ -1131,9 +1147,7 @@ BluetoothGattManager::WriteCharacteristicValue(
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
if (NS_WARN_IF(index == sClients->NoIndex)) {
// Reject the write characteristic value request
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("WriteCharacteristicValue failed"));
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
@ -1214,9 +1228,7 @@ BluetoothGattManager::ReadDescriptorValue(
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
if (NS_WARN_IF(index == sClients->NoIndex)) {
// Reject the read descriptor value request
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("ReadDescriptorValue failed"));
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
@ -1297,9 +1309,7 @@ BluetoothGattManager::WriteDescriptorValue(
size_t index = sClients->IndexOf(aAppUuid, 0 /* Start */, UuidComparator());
if (NS_WARN_IF(index == sClients->NoIndex)) {
// Reject the write descriptor value request
DispatchReplyError(aRunnable,
NS_LITERAL_STRING("WriteDescriptorValue failed"));
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
@ -1352,7 +1362,8 @@ BluetoothGattManager::RegisterClientNotification(BluetoothGattStatus aStatus,
UuidToString(aAppUuid, uuid);
size_t index = sClients->IndexOf(uuid, 0 /* Start */, UuidComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
BluetoothService* bs = BluetoothService::Get();
@ -1447,7 +1458,8 @@ BluetoothGattManager::ConnectNotification(int aConnId,
size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
ClientIfComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
if (aStatus != GATT_STATUS_SUCCESS) {
@ -1499,7 +1511,8 @@ BluetoothGattManager::DisconnectNotification(int aConnId,
size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
ClientIfComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
if (aStatus != GATT_STATUS_SUCCESS) {
@ -1545,7 +1558,7 @@ BluetoothGattManager::SearchCompleteNotification(int aConnId,
size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
ConnIdComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
MOZ_ASSERT(client->mDiscoverRunnable);
@ -1582,7 +1595,7 @@ BluetoothGattManager::SearchResultNotification(
size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
ConnIdComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
// Save to mServices for distributing to application and discovering
// included services, characteristics of this service later
@ -1603,7 +1616,7 @@ BluetoothGattManager::GetCharacteristicNotification(
size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
ConnIdComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
MOZ_ASSERT(client->mDiscoverRunnable);
@ -1655,7 +1668,7 @@ BluetoothGattManager::GetDescriptorNotification(
size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
ConnIdComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
MOZ_ASSERT(client->mDiscoverRunnable);
@ -1699,7 +1712,7 @@ BluetoothGattManager::GetIncludedServiceNotification(
size_t index = sClients->IndexOf(aConnId, 0 /* Start */,
ConnIdComparator());
MOZ_ASSERT(index != sClients->NoIndex);
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
MOZ_ASSERT(client->mDiscoverRunnable);
@ -2018,6 +2031,7 @@ BluetoothGattManager::ReadRemoteRssiNotification(int aClientIf,
size_t index = sClients->IndexOf(aClientIf, 0 /* Start */,
ClientIfComparator());
NS_ENSURE_TRUE_VOID(index != sClients->NoIndex);
nsRefPtr<BluetoothGattClient> client = sClients->ElementAt(index);
if (aStatus != GATT_STATUS_SUCCESS) { // operation failed