discovery: add close() method to plugin interface
MultiPart: 2/3
Change-Id: Ib1b82af15d83af63f1a78a173b7ea4af16016c52
diff --git a/android-lib/src/main/java/io/v/android/impl/google/discovery/plugins/ble/BlePlugin.java b/android-lib/src/main/java/io/v/android/impl/google/discovery/plugins/ble/BlePlugin.java
index a96b1a8..e839716 100644
--- a/android-lib/src/main/java/io/v/android/impl/google/discovery/plugins/ble/BlePlugin.java
+++ b/android-lib/src/main/java/io/v/android/impl/google/discovery/plugins/ble/BlePlugin.java
@@ -74,7 +74,7 @@
private final Context androidContext;
// Set of Ble objects that will be interacted with to perform operations.
- private BluetoothLeAdvertiser bluetoothLeAdvertise;
+ private BluetoothLeAdvertiser bluetoothLeAdvertiser;
private BluetoothLeScanner bluetoothLeScanner;
private BluetoothGattServer bluetoothGattServer;
@@ -105,7 +105,7 @@
throw new IllegalStateException("No permission on BluetoothAdapter");
}
- bluetoothLeAdvertise = bluetoothAdapter.getBluetoothLeAdvertiser();
+ bluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
BluetoothManager manager =
(BluetoothManager) androidContext.getSystemService(Context.BLUETOOTH_SERVICE);
@@ -185,6 +185,10 @@
}
}
+ public void close() {
+ bluetoothGattServer.close();
+ }
+
private long genStamp() {
// We use 8-byte stamp to reflect the current services of the current device.
//
@@ -196,7 +200,7 @@
private void updateAdvertising() {
if (advertiseCallback != null) {
- bluetoothLeAdvertise.stopAdvertising(advertiseCallback);
+ bluetoothLeAdvertiser.stopAdvertising(advertiseCallback);
advertiseCallback = null;
}
if (advertisements.size() == 0) {
@@ -223,7 +227,7 @@
Log.e(TAG, "failed to start advertising " + errorCode);
}
};
- bluetoothLeAdvertise.startAdvertising(
+ bluetoothLeAdvertiser.startAdvertising(
settingsBuilder.build(), builder.build(), advertiseCallback);
}
diff --git a/lib/src/main/java/io/v/impl/google/lib/discovery/Plugin.java b/lib/src/main/java/io/v/impl/google/lib/discovery/Plugin.java
index 93219ab..8929a8d 100644
--- a/lib/src/main/java/io/v/impl/google/lib/discovery/Plugin.java
+++ b/lib/src/main/java/io/v/impl/google/lib/discovery/Plugin.java
@@ -64,4 +64,11 @@
* @throws Exception if scanning couldn't be started
*/
void stopScan(ScanHandler handler) throws Exception;
+
+ /**
+ * Closes the plugin.
+ * <p>
+ * This will be called after all active tasks have been cancelled.
+ */
+ void close();
}