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

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

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

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

@ -3247,7 +3247,7 @@ class SetPinCodeTask : public Task
{
public:
SetPinCodeTask(const BluetoothAddress& aDeviceAddress,
const nsACString& aPinCode,
const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable)
: mDeviceAddress(aDeviceAddress)
, mPinCode(aPinCode)
@ -3281,7 +3281,19 @@ public:
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,
DBUS_TYPE_STRING, &pinCode,
@ -3302,14 +3314,14 @@ public:
private:
const BluetoothAddress mDeviceAddress;
const nsCString mPinCode;
const BluetoothPinCode mPinCode;
RefPtr<BluetoothReplyRunnable> mRunnable;
};
void
BluetoothDBusService::PinReplyInternal(
const BluetoothAddress& aDeviceAddress, bool aAccept,
const nsAString& aPinCode, BluetoothReplyRunnable* aRunnable)
const BluetoothPinCode& aPinCode, BluetoothReplyRunnable* aRunnable)
{
// Legacy interface used by Bluedroid only.
}
@ -3324,12 +3336,10 @@ BluetoothDBusService::SspReplyInternal(
void
BluetoothDBusService::SetPinCodeInternal(const BluetoothAddress& aDeviceAddress,
const nsAString& aPinCode,
const BluetoothPinCode& aPinCode,
BluetoothReplyRunnable* aRunnable)
{
Task* task = new SetPinCodeTask(aDeviceAddress,
NS_ConvertUTF16toUTF8(aPinCode),
aRunnable);
Task* task = new SetPinCodeTask(aDeviceAddress, aPinCode, aRunnable);
DispatchToDBusThread(task);
}

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

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

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

@ -674,6 +674,24 @@ struct BluetoothUuid {
struct BluetoothPinCode {
uint8_t mPinCode[16]; /* not \0-terminated */
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 {

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

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

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

@ -61,6 +61,21 @@ StringToAddress(const nsAString& aString, BluetoothAddress& aAddress)
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
StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
{
@ -69,7 +84,7 @@ StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
auto len = stringUTF8.Length();
if (len > sizeof(aPinCode.mPinCode)) {
BT_LOGR("Service-name string too long");
BT_LOGR("Pin-code string too long");
return NS_ERROR_ILLEGAL_VALUE;
}

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

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

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

@ -86,10 +86,15 @@ BluetoothPairingHandle::SetPinCode(const nsAString& aPinCode, ErrorResult& aRv)
promise,
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();
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));
return promise.forget();
@ -154,7 +159,8 @@ BluetoothPairingHandle::Reject(ErrorResult& aRv)
BT_ENSURE_TRUE_REJECT(bs, promise, NS_ERROR_NOT_AVAILABLE);
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));
} else { // Ssp request
BluetoothSspVariant variant;

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

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

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

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

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

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