Skip to content

Commit

Permalink
WebBluetooth Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
dati91 committed Sep 6, 2016
1 parent 5f702d6 commit ccc66d0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
31 changes: 15 additions & 16 deletions components/net/bluetooth_thread.rs
Expand Up @@ -4,7 +4,6 @@

use device::bluetooth::BluetoothAdapter;
use device::bluetooth::BluetoothDevice;
use device::bluetooth::BluetoothDiscoverySession;
use device::bluetooth::BluetoothGATTCharacteristic;
use device::bluetooth::BluetoothGATTDescriptor;
use device::bluetooth::BluetoothGATTService;
Expand Down Expand Up @@ -294,8 +293,8 @@ impl BluetoothManager {
None => vec!(),
};
for service in &services {
self.cached_services.insert(service.get_object_path(), service.clone());
self.service_to_device.insert(service.get_object_path(), device_id.to_owned());
self.cached_services.insert(service.get_id(), service.clone());
self.service_to_device.insert(service.get_id(), device_id.to_owned());
}
services
}
Expand Down Expand Up @@ -332,8 +331,8 @@ impl BluetoothManager {
};

for characteristic in &characteristics {
self.cached_characteristics.insert(characteristic.get_object_path(), characteristic.clone());
self.characteristic_to_service.insert(characteristic.get_object_path(), service_id.to_owned());
self.cached_characteristics.insert(characteristic.get_id(), characteristic.clone());
self.characteristic_to_service.insert(characteristic.get_id(), service_id.to_owned());
}
characteristics
}
Expand Down Expand Up @@ -395,8 +394,8 @@ impl BluetoothManager {
};

for descriptor in &descriptors {
self.cached_descriptors.insert(descriptor.get_object_path(), descriptor.clone());
self.descriptor_to_characteristic.insert(descriptor.get_object_path(), characteristic_id.to_owned());
self.cached_descriptors.insert(descriptor.get_id(), descriptor.clone());
self.descriptor_to_characteristic.insert(descriptor.get_id(), characteristic_id.to_owned());
}
descriptors
}
Expand Down Expand Up @@ -432,7 +431,7 @@ impl BluetoothManager {
options: RequestDeviceoptions,
sender: IpcSender<BluetoothResult<BluetoothDeviceMsg>>) {
let mut adapter = get_adapter_or_return_error!(self, sender);
if let Some(ref session) = BluetoothDiscoverySession::create_session(adapter.get_object_path()).ok() {
if let Ok(ref session) = adapter.create_discovery_session() {
if session.start_discovery().is_ok() {
thread::sleep(Duration::from_millis(DISCOVERY_TIMEOUT_MS));
}
Expand Down Expand Up @@ -526,7 +525,7 @@ impl BluetoothManager {
return drop(sender.send(Ok(BluetoothServiceMsg {
uuid: uuid,
is_primary: true,
instance_id: service.get_object_path(),
instance_id: service.get_id(),
})));
}
}
Expand Down Expand Up @@ -558,7 +557,7 @@ impl BluetoothManager {
services_vec.push(BluetoothServiceMsg {
uuid: uuid,
is_primary: true,
instance_id: service.get_object_path(),
instance_id: service.get_id(),
});
}
}
Expand Down Expand Up @@ -589,7 +588,7 @@ impl BluetoothManager {
return drop(sender.send(Ok(BluetoothServiceMsg {
uuid: uuid,
is_primary: service.is_primary().unwrap_or(false),
instance_id: service.get_object_path(),
instance_id: service.get_id(),
})));
}
}
Expand All @@ -616,7 +615,7 @@ impl BluetoothManager {
services_vec.push(BluetoothServiceMsg {
uuid: service_uuid,
is_primary: service.is_primary().unwrap_or(false),
instance_id: service.get_object_path(),
instance_id: service.get_id(),
});
}
}
Expand Down Expand Up @@ -644,7 +643,7 @@ impl BluetoothManager {
let properties = self.get_characteristic_properties(&characteristic);
let message = Ok(BluetoothCharacteristicMsg {
uuid: uuid,
instance_id: characteristic.get_object_path(),
instance_id: characteristic.get_id(),
broadcast: properties.contains(BROADCAST),
read: properties.contains(READ),
write_without_response: properties.contains(WRITE_WITHOUT_RESPONSE),
Expand Down Expand Up @@ -680,7 +679,7 @@ impl BluetoothManager {
characteristics_vec.push(
BluetoothCharacteristicMsg {
uuid: uuid,
instance_id: characteristic.get_object_path(),
instance_id: characteristic.get_id(),
broadcast: properties.contains(BROADCAST),
read: properties.contains(READ),
write_without_response: properties.contains(WRITE_WITHOUT_RESPONSE),
Expand Down Expand Up @@ -713,7 +712,7 @@ impl BluetoothManager {
if let Ok(uuid) = descriptor.get_uuid() {
return drop(sender.send(Ok(BluetoothDescriptorMsg {
uuid: uuid,
instance_id: descriptor.get_object_path(),
instance_id: descriptor.get_id(),
})));
}
}
Expand All @@ -737,7 +736,7 @@ impl BluetoothManager {
if let Ok(uuid) = descriptor.get_uuid() {
descriptors_vec.push(BluetoothDescriptorMsg {
uuid: uuid,
instance_id: descriptor.get_object_path(),
instance_id: descriptor.get_id(),
});
}
}
Expand Down
15 changes: 11 additions & 4 deletions components/servo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions ports/cef/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions python/servo/package_commands.py
Expand Up @@ -135,6 +135,15 @@ def package(self, release=False, dev=False, android=None, debug=False, debugger=

target_dir = path.dirname(binary_path)
output_apk = "{}.apk".format(binary_path)
blurdroid_path = find_dep_path_newest('blurdroid', binary_path)
if blurdroid_path is None:
print("Could not find blurdroid package; perhaps you haven't built Servo.")
return 1
else:
dir_to_libs = path.join("support", "android", "apk", "libs")
if not path.exists(dir_to_libs):
os.makedirs(dir_to_libs)
shutil.copy2(blurdroid_path + '/out/blurdroid.jar', dir_to_libs)
try:
with cd(path.join("support", "android", "build-apk")):
subprocess.check_call(["cargo", "run", "--", dev_flag, "-o", output_apk, "-t", target_dir,
Expand Down
3 changes: 3 additions & 0 deletions support/android/apk/AndroidManifest.xml
Expand Up @@ -8,9 +8,12 @@
<uses-sdk android:minSdkVersion="18" />

<uses-feature android:glEsVersion="0x00020000" android:required="true"></uses-feature>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<application android:label="Servo" android:icon="@mipmap/servo">
<activity android:name="com.mozilla.servo.MainActivity"
Expand Down
Expand Up @@ -13,6 +13,7 @@ public class MainActivity extends android.app.NativeActivity {
private static final String LOGTAG="servo_wrapper";
static {
Log.i(LOGTAG, "Loading the NativeActivity");
System.loadLibrary("main");
}

private void set_url(String url) {
Expand Down

0 comments on commit ccc66d0

Please sign in to comment.