mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 02:35:41 +00:00
Bug 1207011 - Send Bluetooth OBEX End-of-Body header individually to improve the compatibility with other devices. r=btian
This commit is contained in:
parent
9bd18a2bc7
commit
9d55788304
@ -842,8 +842,9 @@ BluetoothPbapManager::ReplyToGet(uint16_t aPhonebookSize)
|
|||||||
* - Part 2: [headerId:1][length:2][PhonebookSize:4]
|
* - Part 2: [headerId:1][length:2][PhonebookSize:4]
|
||||||
* - Part 3: [headerId:1][length:2][EndOfBody:0]
|
* - Part 3: [headerId:1][length:2][EndOfBody:0]
|
||||||
* Otherwise,
|
* Otherwise,
|
||||||
* - Part 2: [headerId:1][length:2][Body:var]
|
* - Part 2a: [headerId:1][length:2][EndOfBody:0]
|
||||||
* - (optional) Part 3: [headerId:1][length:2][EndOfBody:0]
|
* or
|
||||||
|
* - Part 2b: [headerId:1][length:2][Body:var]
|
||||||
*/
|
*/
|
||||||
uint8_t* res = new uint8_t[mRemoteMaxPacketLength];
|
uint8_t* res = new uint8_t[mRemoteMaxPacketLength];
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
@ -883,40 +884,54 @@ BluetoothPbapManager::ReplyToGet(uint16_t aPhonebookSize)
|
|||||||
} else {
|
} else {
|
||||||
MOZ_ASSERT(mVCardDataStream);
|
MOZ_ASSERT(mVCardDataStream);
|
||||||
|
|
||||||
// ---- Part 2: [headerId:1][length:2][Body:var] ---- //
|
uint64_t bytesAvailable = 0;
|
||||||
// Compute remaining packet size to append Body, excluding Body's header
|
nsresult rv = mVCardDataStream->Available(&bytesAvailable);
|
||||||
uint32_t remainingPacketSize =
|
|
||||||
mRemoteMaxPacketLength - kObexBodyHeaderSize - index;
|
|
||||||
|
|
||||||
// Read vCard data from input stream
|
|
||||||
uint32_t numRead = 0;
|
|
||||||
nsAutoArrayPtr<char> buf(new char[remainingPacketSize]);
|
|
||||||
nsresult rv = mVCardDataStream->Read(buf, remainingPacketSize, &numRead);
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
BT_LOGR("Failed to read from input stream. rv=0x%x",
|
BT_LOGR("Failed to get available bytes from input stream. rv=0x%x",
|
||||||
static_cast<uint32_t>(rv));
|
static_cast<uint32_t>(rv));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numRead) {
|
/*
|
||||||
index += AppendHeaderBody(&res[index],
|
* In practice, some platforms can only handle zero length End-of-Body
|
||||||
remainingPacketSize,
|
* header separately with Body header.
|
||||||
(uint8_t*) buf.forget(),
|
* Thus, append End-of-Body only if the data stream had been sent out,
|
||||||
numRead);
|
* otherwise, send 'Continue' to request for next GET request.
|
||||||
}
|
*/
|
||||||
|
if (!bytesAvailable) {
|
||||||
// More GET requests are required if remaining packet size isn't
|
// ---- Part 2a: [headerId:1][length:2][EndOfBody:0] ---- //
|
||||||
// enough for 1) number of bytes read plus 2) one EndOfBody's header
|
|
||||||
if (numRead + kObexBodyHeaderSize > remainingPacketSize) {
|
|
||||||
opcode = ObexResponseCode::Continue;
|
|
||||||
} else {
|
|
||||||
// ---- Part 3: [headerId:1][length:2][EndOfBody:0] ---- //
|
|
||||||
opcode = ObexResponseCode::Success;
|
|
||||||
index += AppendHeaderEndOfBody(&res[index]);
|
index += AppendHeaderEndOfBody(&res[index]);
|
||||||
|
|
||||||
// Close input stream
|
// Close input stream
|
||||||
mVCardDataStream->Close();
|
mVCardDataStream->Close();
|
||||||
mVCardDataStream = nullptr;
|
mVCardDataStream = nullptr;
|
||||||
|
|
||||||
|
opcode = ObexResponseCode::Success;
|
||||||
|
} else {
|
||||||
|
// Compute remaining packet size to append Body, excluding Body's header
|
||||||
|
uint32_t remainingPacketSize =
|
||||||
|
mRemoteMaxPacketLength - kObexBodyHeaderSize - index;
|
||||||
|
|
||||||
|
// Read vCard data from input stream
|
||||||
|
uint32_t numRead = 0;
|
||||||
|
nsAutoArrayPtr<char> buf(new char[remainingPacketSize]);
|
||||||
|
rv = mVCardDataStream->Read(buf, remainingPacketSize, &numRead);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
BT_LOGR("Failed to read from input stream. rv=0x%x",
|
||||||
|
static_cast<uint32_t>(rv));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// |numRead| must be non-zero as |bytesAvailable| is non-zero
|
||||||
|
MOZ_ASSERT(numRead);
|
||||||
|
|
||||||
|
// ---- Part 2b: [headerId:1][length:2][Body:var] ---- //
|
||||||
|
index += AppendHeaderBody(&res[index],
|
||||||
|
remainingPacketSize,
|
||||||
|
(uint8_t*) buf.forget(),
|
||||||
|
numRead);
|
||||||
|
|
||||||
|
opcode = ObexResponseCode::Continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user