Bug 1220121: Convert IPDL of Bluetooth Core API to |BluetoothPinCode|, r=brsun

This commit is contained in:
Thomas Zimmermann 2015-11-12 11:23:35 +01:00
Родитель c1ee8d6d40
Коммит 0b0f22bed8
12 изменённых файлов: 82 добавлений и 39 удалений

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

@ -1399,26 +1399,19 @@ private:
void void
BluetoothServiceBluedroid::PinReplyInternal( BluetoothServiceBluedroid::PinReplyInternal(
const BluetoothAddress& aDeviceAddress, bool aAccept, const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable); ENSURE_BLUETOOTH_IS_READY_VOID(aRunnable);
BluetoothPinCode pinCode; sBtInterface->PinReply(aDeviceAddress, aAccept, aPinCode,
auto rv = StringToPinCode(aPinCode, pinCode);
if (NS_FAILED(rv)) {
DispatchReplyError(aRunnable, STATUS_PARM_INVALID);
return;
}
sBtInterface->PinReply(aDeviceAddress, aAccept, pinCode,
new PinReplyResultHandler(aRunnable)); new PinReplyResultHandler(aRunnable));
} }
void void
BluetoothServiceBluedroid::SetPinCodeInternal( BluetoothServiceBluedroid::SetPinCodeInternal(
const BluetoothAddress& aDeviceAddress, const nsAString& aPinCode, const BluetoothAddress& aDeviceAddress, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
// Legacy method used by BlueZ only. // Legacy method used by BlueZ only.

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

@ -87,7 +87,7 @@ public:
virtual void virtual void
PinReplyInternal(const BluetoothAddress& aDeviceAddress, PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept, bool aAccept,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void
@ -97,7 +97,7 @@ public:
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void
SetPinCodeInternal(const BluetoothAddress& aDeviceAddress, SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void

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

@ -3247,7 +3247,7 @@ class SetPinCodeTask : public Task
{ {
public: public:
SetPinCodeTask(const BluetoothAddress& aDeviceAddress, SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
const nsACString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress) : mDeviceAddress(aDeviceAddress)
, mPinCode(aPinCode) , mPinCode(aPinCode)
@ -3281,7 +3281,19 @@ public:
return; return;
} }
const char* pinCode = mPinCode.get(); nsAutoString pinCodeStr;
if (NS_FAILED(PinCodeToString(mPinCode, pinCodeStr))) {
BT_WARNING("%s: Cannot convert pin code to string.", __FUNCTION__);
dbus_message_unref(msg);
dbus_message_unref(reply);
errorStr.AssignLiteral("Cannot convert pin code to string.");
DispatchBluetoothReply(mRunnable, v, errorStr);
return;
}
auto utf8PinCodeStr = NS_ConvertUTF16toUTF8(pinCodeStr);
const char* pinCode = utf8PinCodeStr.get();
if (!dbus_message_append_args(reply, if (!dbus_message_append_args(reply,
DBUS_TYPE_STRING, &pinCode, DBUS_TYPE_STRING, &pinCode,
@ -3302,14 +3314,14 @@ public:
private: private:
const BluetoothAddress mDeviceAddress; const BluetoothAddress mDeviceAddress;
const nsCString mPinCode; const BluetoothPinCode mPinCode;
RefPtr<BluetoothReplyRunnable> mRunnable; RefPtr<BluetoothReplyRunnable> mRunnable;
}; };
void void
BluetoothDBusService::PinReplyInternal( BluetoothDBusService::PinReplyInternal(
const BluetoothAddress& aDeviceAddress, bool aAccept, const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
{ {
// Legacy interface used by Bluedroid only. // Legacy interface used by Bluedroid only.
} }
@ -3324,12 +3336,10 @@ BluetoothDBusService::SspReplyInternal(
void void
BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress, BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
Task* task = new SetPinCodeTask(aDeviceAddress, Task* task = new SetPinCodeTask(aDeviceAddress, aPinCode, aRunnable);
NS_ConvertUTF16toUTF8(aPinCode),
aRunnable);
DispatchToDBusThread(task); DispatchToDBusThread(task);
} }

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

@ -99,7 +99,7 @@ public:
virtual void virtual void
PinReplyInternal(const BluetoothAddress& aDeviceAddress, PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept, bool aAccept,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void
@ -110,7 +110,7 @@ public:
virtual void virtual void
SetPinCodeInternal(const BluetoothAddress& aDeviceAddress, SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void

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

@ -674,6 +674,24 @@ struct BluetoothUuid {
struct BluetoothPinCode { struct BluetoothPinCode {
uint8_t mPinCode[16]; /* not \0-terminated */ uint8_t mPinCode[16]; /* not \0-terminated */
uint8_t mLength; uint8_t mLength;
BluetoothPinCode()
: mLength(0)
{
std::fill(mPinCode, mPinCode + MOZ_ARRAY_LENGTH(mPinCode), 0);
}
bool operator==(const BluetoothPinCode& aRhs) const
{
MOZ_ASSERT(mLength <= MOZ_ARRAY_LENGTH(mPinCode));
return (mLength == aRhs.mLength) &&
std::equal(aRhs.mPinCode, aRhs.mPinCode + aRhs.mLength, mPinCode);
}
bool operator!=(const BluetoothPinCode& aRhs) const
{
return !operator==(aRhs);
}
}; };
struct BluetoothServiceName { struct BluetoothServiceName {

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

@ -244,7 +244,7 @@ public:
virtual void virtual void
PinReplyInternal(const BluetoothAddress& aDeviceAddress, PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept, bool aAccept,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
virtual void virtual void
@ -258,7 +258,7 @@ public:
*/ */
virtual void virtual void
SetPinCodeInternal(const BluetoothAddress& aDeviceAddress, SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
/** /**

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

@ -61,6 +61,21 @@ StringToAddress(const nsAString& aString, BluetoothAddress& aAddress)
return NS_OK; return NS_OK;
} }
nsresult
PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString)
{
if (aPinCode.mLength > sizeof(aPinCode.mPinCode)) {
BT_LOGR("Pin-code string too long");
return NS_ERROR_ILLEGAL_VALUE;
}
aString = NS_ConvertUTF8toUTF16(
nsCString(reinterpret_cast<const char*>(aPinCode.mPinCode),
aPinCode.mLength));
return NS_OK;
}
nsresult nsresult
StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode) StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
{ {
@ -69,7 +84,7 @@ StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
auto len = stringUTF8.Length(); auto len = stringUTF8.Length();
if (len > sizeof(aPinCode.mPinCode)) { if (len > sizeof(aPinCode.mPinCode)) {
BT_LOGR("Service-name string too long"); BT_LOGR("Pin-code string too long");
return NS_ERROR_ILLEGAL_VALUE; return NS_ERROR_ILLEGAL_VALUE;
} }

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

@ -37,6 +37,9 @@ StringToAddress(const nsAString& aString, BluetoothAddress& aAddress);
// Pin code/string conversion // Pin code/string conversion
// //
nsresult
PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString);
nsresult nsresult
StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode); StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode);

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

@ -86,10 +86,15 @@ BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv)
promise, promise,
NS_ERROR_DOM_INVALID_STATE_ERR); NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothPinCode pinCode;
BT_ENSURE_TRUE_REJECT(NS_SUCCEEDED(StringToPinCode(aPinCode, pinCode)),
promise,
NS_ERROR_DOM_INVALID_STATE_ERR);
BluetoothService* bs = BluetoothService::Get(); BluetoothService* bs = BluetoothService::Get();
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
bs->PinReplyInternal(deviceAddress, true /* accept */, aPinCode, bs->PinReplyInternal(deviceAddress, true /* accept */, pinCode,
new BluetoothVoidReplyRunnable(nullptr, promise)); new BluetoothVoidReplyRunnable(nullptr, promise));
return promise.forget(); return promise.forget();
@ -154,7 +159,8 @@ BluetoothPairingHandle::Reject(ErrorResult& aRv)
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE); BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request if (mType.EqualsLiteral(PAIRING_REQ_TYPE_ENTERPINCODE)) { // Pin request
bs->PinReplyInternal(deviceAddress, false /* aAccept */, EmptyString(), bs->PinReplyInternal(deviceAddress, false /* aAccept */,
BluetoothPinCode(),
new BluetoothVoidReplyRunnable(nullptr, promise)); new BluetoothVoidReplyRunnable(nullptr, promise));
} else { // Ssp request } else { // Ssp request
BluetoothSspVariant variant; BluetoothSspVariant variant;

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

@ -221,12 +221,9 @@ BluetoothServiceChildProcess::UpdateSdpRecords(const BluetoothAddress& aDeviceAd
void void
BluetoothServiceChildProcess::PinReplyInternal( BluetoothServiceChildProcess::PinReplyInternal(
const BluetoothAddress& aDeviceAddress, bool aAccept, const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable) const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable, PinReplyRequest(aDeviceAddress, aAccept, aPinCode));
PinReplyRequest(aDeviceAddress,
aAccept,
nsString(aPinCode)));
} }
void void
@ -241,11 +238,10 @@ BluetoothServiceChildProcess::SspReplyInternal(
void void
BluetoothServiceChildProcess::SetPinCodeInternal( BluetoothServiceChildProcess::SetPinCodeInternal(
const BluetoothAddress& aDeviceAddress, const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
SendRequest(aRunnable, SendRequest(aRunnable, SetPinCodeRequest(aDeviceAddress, aPinCode));
SetPinCodeRequest(aDeviceAddress, nsString(aPinCode)));
} }
void void

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

@ -92,7 +92,7 @@ public:
virtual void virtual void
SetPinCodeInternal(const BluetoothAddress& aDeviceAddress, SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void
@ -109,7 +109,7 @@ public:
virtual void virtual void
PinReplyInternal(const BluetoothAddress& aDeviceAddress, PinReplyInternal(const BluetoothAddress& aDeviceAddress,
bool aAccept, bool aAccept,
const nsAString& aPinCode, const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void

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

@ -16,6 +16,8 @@ using mozilla::dom::bluetooth::BluetoothAddress
from "mozilla/dom/bluetooth/BluetoothCommon.h"; from "mozilla/dom/bluetooth/BluetoothCommon.h";
using mozilla::dom::bluetooth::BluetoothObjectType using mozilla::dom::bluetooth::BluetoothObjectType
from "mozilla/dom/bluetooth/BluetoothCommon.h"; from "mozilla/dom/bluetooth/BluetoothCommon.h";
using mozilla::dom::bluetooth::BluetoothPinCode
from "mozilla/dom/bluetooth/BluetoothCommon.h";
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -81,7 +83,7 @@ struct PinReplyRequest
{ {
BluetoothAddress address; BluetoothAddress address;
bool accept; bool accept;
nsString pinCode; BluetoothPinCode pinCode;
}; };
struct SspReplyRequest struct SspReplyRequest
@ -94,7 +96,7 @@ struct SspReplyRequest
struct SetPinCodeRequest struct SetPinCodeRequest
{ {
BluetoothAddress address; BluetoothAddress address;
nsString pincode; BluetoothPinCode pincode;
}; };
struct SetPasskeyRequest struct SetPasskeyRequest