Commit a2b1d009 authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Use stringified JSON for bluetooth sdp attributes.

Recently, Mojo wire format change was introduced
for native structure.
https://chromium.googlesource.com/chromium/src/+/fd907634b5ea956b34bd1672c084089aad2150cd
It causes a protocol mismatch between ARC and Chrome.
Unfortunately, rolled libmojo is too old, so we cannot
use values.mojom now. As its workaround,
this CL stringifies the JSON value if necessary,
and use it for the communication.

Note that this is breaking change. Though, the protocol is already
broken, so we don't much care about it.

BUG=767313
TEST=Ran CTS.

Change-Id: Iaaf28065aa7cde0ce17d7231da0571312f23772d
Reviewed-on: https://chromium-review.googlesource.com/691495
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarKazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: default avatarMattias Nissler <mnissler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506678}
parent 745bf244
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -124,29 +126,28 @@ TypeConverter<arc::mojom::BluetoothSdpAttributePtr, ...@@ -124,29 +126,28 @@ TypeConverter<arc::mojom::BluetoothSdpAttributePtr,
switch (result->type) { switch (result->type) {
case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE:
result->value.Append(std::make_unique<base::Value>());
break;
case bluez::BluetoothServiceAttributeValueBlueZ::UINT: case bluez::BluetoothServiceAttributeValueBlueZ::UINT:
case bluez::BluetoothServiceAttributeValueBlueZ::INT: case bluez::BluetoothServiceAttributeValueBlueZ::INT:
case bluez::BluetoothServiceAttributeValueBlueZ::UUID: case bluez::BluetoothServiceAttributeValueBlueZ::UUID:
case bluez::BluetoothServiceAttributeValueBlueZ::STRING: case bluez::BluetoothServiceAttributeValueBlueZ::STRING:
case bluez::BluetoothServiceAttributeValueBlueZ::URL: case bluez::BluetoothServiceAttributeValueBlueZ::URL:
case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: {
result->type_size = attr_bluez.size(); result->type_size = attr_bluez.size();
result->value.Append(attr_bluez.value().CreateDeepCopy()); std::string json;
base::JSONWriter::Write(attr_bluez.value(), &json);
result->json_value = std::move(json);
break; break;
}
case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE:
if (depth + 1 >= arc::kBluetoothSDPMaxDepth) { if (depth + 1 >= arc::kBluetoothSDPMaxDepth) {
result->type = bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE; result->type = bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE;
result->type_size = 0; result->type_size = 0;
result->value.Append(std::make_unique<base::Value>());
return result; return result;
} }
for (const auto& child : attr_bluez.sequence()) { for (const auto& child : attr_bluez.sequence()) {
result->sequence.push_back(Convert(child, depth + 1)); result->sequence.push_back(Convert(child, depth + 1));
} }
result->type_size = result->sequence.size(); result->type_size = result->sequence.size();
result->value.Clear();
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -164,24 +165,21 @@ TypeConverter<bluez::BluetoothServiceAttributeValueBlueZ, ...@@ -164,24 +165,21 @@ TypeConverter<bluez::BluetoothServiceAttributeValueBlueZ,
switch (type) { switch (type) {
case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE: case bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE:
return bluez::BluetoothServiceAttributeValueBlueZ();
case bluez::BluetoothServiceAttributeValueBlueZ::UINT: case bluez::BluetoothServiceAttributeValueBlueZ::UINT:
case bluez::BluetoothServiceAttributeValueBlueZ::INT: case bluez::BluetoothServiceAttributeValueBlueZ::INT:
case bluez::BluetoothServiceAttributeValueBlueZ::UUID: case bluez::BluetoothServiceAttributeValueBlueZ::UUID:
case bluez::BluetoothServiceAttributeValueBlueZ::STRING: case bluez::BluetoothServiceAttributeValueBlueZ::STRING:
case bluez::BluetoothServiceAttributeValueBlueZ::URL: case bluez::BluetoothServiceAttributeValueBlueZ::URL:
case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: { case bluez::BluetoothServiceAttributeValueBlueZ::BOOL: {
if (attr->value.GetSize() != 1) { if (!attr->json_value.has_value()) {
return bluez::BluetoothServiceAttributeValueBlueZ( return bluez::BluetoothServiceAttributeValueBlueZ(
bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE, 0, bluez::BluetoothServiceAttributeValueBlueZ::NULLTYPE, 0,
std::make_unique<base::Value>()); std::make_unique<base::Value>());
} }
std::unique_ptr<base::Value> value;
attr->value.Remove(0, &value);
return bluez::BluetoothServiceAttributeValueBlueZ( return bluez::BluetoothServiceAttributeValueBlueZ(
type, static_cast<size_t>(attr->type_size), std::move(value)); type, static_cast<size_t>(attr->type_size),
base::JSONReader::Read(attr->json_value.value()));
} }
case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: { case bluez::BluetoothServiceAttributeValueBlueZ::SEQUENCE: {
if (depth + 1 >= arc::kBluetoothSDPMaxDepth || attr->sequence.empty()) { if (depth + 1 >= arc::kBluetoothSDPMaxDepth || attr->sequence.empty()) {
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
module arc.mojom; module arc.mojom;
import "mojo/common/values.mojom";
[Extensible] [Extensible]
enum BluetoothAdapterState { enum BluetoothAdapterState {
OFF = 0, OFF = 0,
...@@ -272,8 +270,17 @@ enum BluetoothSdpAttributeType { ...@@ -272,8 +270,17 @@ enum BluetoothSdpAttributeType {
struct BluetoothSdpAttribute { struct BluetoothSdpAttribute {
BluetoothSdpAttributeType type; BluetoothSdpAttributeType type;
uint32 type_size; uint32 type_size;
mojo.common.mojom.LegacyListValue value;
array<BluetoothSdpAttribute> sequence; array<BluetoothSdpAttribute> sequence;
// Holds the stringified JSON value of this attribute.
// If the type is NULLTYPE or SEQUENCE, this is empty.
// Explicitly specify the ordinal @3, because introducing this is a breaking
// change. This field is introduced between version 7 and 8, though
// MinVersion is not annotated because of breaking change, too.
// See details in the bug linked below.
// TODO(crbug.com/767313): Use mojo/common/values.mojom, when new libmojo
// (440057 or later) is rolled to ARC repository.
string? json_value@3;
}; };
struct BluetoothSdpRecord { struct BluetoothSdpRecord {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment