diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5102508 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,20 @@ +name: Build + +on: + push: + branches: + - 'develop' + pull_request: + branches: + - 'master' + +jobs: + build: + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: pre-build + run: chmod +x ./gradlew + - name: build + run: ./gradlew clean assemble \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/prepRelease.yml similarity index 86% rename from .github/workflows/ci.yml rename to .github/workflows/prepRelease.yml index a023081..32d35a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/prepRelease.yml @@ -1,16 +1,16 @@ -name: CI +name: Prepare Release on: push: branches: - - 'develop' + - 'release' jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: pre-build run: chmod +x ./gradlew - name: build @@ -28,4 +28,4 @@ jobs: uses: ad-m/github-push-action@master with: github_token: ${{ secrets.GITHUB_TOKEN }} - branch: 'develop' + branch: 'release' diff --git a/README.md b/README.md index b474734..1d6877d 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,8 @@ This sample app includes client bridging and bound witnessing with a BLE server ## Contributing +Please note that any contributions must clear the `release` branch. + ## License See the [LICENSE](LICENSE) file for license details. diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleClient.kt b/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleClient.kt index 645535e..fe7e3a0 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleClient.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleClient.kt @@ -8,9 +8,7 @@ import network.xyo.ble.generic.devices.XYBluetoothDevice import network.xyo.ble.generic.gatt.peripheral.XYBluetoothResult import network.xyo.ble.generic.scanner.XYSmartScan import network.xyo.ble.generic.scanner.XYSmartScanModern -import network.xyo.sdk.bluetooth.client.XyoBluetoothClient -import network.xyo.sdk.bluetooth.client.XyoBridgeX -import network.xyo.sdk.bluetooth.client.XyoSentinelX +import network.xyo.sdk.bluetooth.client.* import network.xyo.sdkcorekotlin.boundWitness.XyoBoundWitness import network.xyo.sdkcorekotlin.crypto.signing.ecdsa.secp256k.XyoSha256WithSecp256K import network.xyo.sdkcorekotlin.network.XyoNetworkHandler @@ -31,6 +29,11 @@ class XyoBleClient( override var autoBridge: Boolean = false override var acceptBridging: Boolean = false + + override var deviceCount = 0 + override var xyoDeviceCount = 0 + override var nearbyXyoDeviceCount = 0 + var supportBridgeX = false var supportSentinelX = false var minimumRssi = -70 @@ -56,6 +59,23 @@ class XyoBleClient( } private val scannerListener = object : XYSmartScan.Listener() { + override fun entered(device: XYBluetoothDevice) { + super.entered(device) + deviceCount++ + if (device is XyoBluetoothClient) { + log.info("Xyo Device Entered: ${device.id}") + xyoDeviceCount++ + } + } + + override fun exited(device: XYBluetoothDevice) { + super.exited(device) + deviceCount-- + if (device is XyoBluetoothClient) { + log.info("Xyo Device Exited: ${device.id}") + xyoDeviceCount-- + } + } override fun detected(device: XYBluetoothDevice) { super.detected(device) if (this@XyoBleClient.autoBoundWitness) { @@ -78,6 +98,7 @@ class XyoBleClient( return } } + nearbyXyoDeviceCount++ GlobalScope.launch { tryBoundWitnessWithDevice(client) } @@ -133,6 +154,8 @@ class XyoBleClient( XyoBluetoothClient.enable(true) XyoBridgeX.enable(true) XyoSentinelX.enable(true) + XyoIosAppX.enable(true) + XyoAndroidAppX.enable(true) XyoSha256WithSecp256K.enable() this.scanner = XYSmartScanModern(context) this.scanner.addListener("xyo_client", this.scannerListener) diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleServer.kt b/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleServer.kt index 800319f..2fb084c 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleServer.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/XyoBleServer.kt @@ -71,6 +71,7 @@ class XyoBleServer( val bw = relayNode.boundWitness(handler, procedureCatalog).await() relayNode.removeListener("XyoBleServer") boundWitnessCompleted(null, bw, errorMessage) + pipe.close().await() return@launch } } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/XyoClient.kt b/xyo-android-library/src/main/java/network/xyo/sdk/XyoClient.kt index 7119375..06ce727 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/XyoClient.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/XyoClient.kt @@ -10,4 +10,7 @@ abstract class XyoClient( ) : XyoBoundWitnessTarget(relayNode, procedureCatalog) { // this is not a parameter since scanning has to start off of false open var scan: Boolean = false + open var deviceCount = 0 + open var xyoDeviceCount = 0 + open var nearbyXyoDeviceCount = 0 } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoAndroidAppX.kt b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoAndroidAppX.kt index 2761653..2ee48c4 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoAndroidAppX.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoAndroidAppX.kt @@ -34,16 +34,16 @@ open class XyoAndroidAppX: XyoBluetoothClient{ XYBluetoothDevice> ) { val hash = hashFromScanResult(scanResult) - val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - XyoAndroidAppX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) - } else { - XyoAndroidAppX(context, scanResult, hash) - } - val foundDevice = foundDevices[hash] - if (foundDevice != null) { - foundDevice.rssi = scanResult.rssi - foundDevice.updateBluetoothDevice(scanResult.device) + val existingDevice = globalDevices[hash] + if (existingDevice != null) { + existingDevice.rssi = scanResult.rssi + existingDevice.updateBluetoothDevice(scanResult.device) } else { + val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + XyoAndroidAppX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) + } else { + XyoAndroidAppX(context, scanResult, hash) + } foundDevices[hash] = createdDevice globalDevices[hash] = createdDevice } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBluetoothClient.kt b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBluetoothClient.kt index 9e7b174..e56b317 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBluetoothClient.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBluetoothClient.kt @@ -242,33 +242,39 @@ open class XyoBluetoothClient : XYIBeaconBluetoothDevice { ) { val hash = hashFromScanResult(scanResult) + val existingDevice = globalDevices[hash] + if (existingDevice != null) { + log.info("Device Found: $hash") + existingDevice.rssi = scanResult.rssi + existingDevice.updateBluetoothDevice(scanResult.device) + } else { + log.info("Device Creating: $hash") + val ad = scanResult.scanRecord?.getManufacturerSpecificData(0x4c) + + if (ad?.size == 23) { + val id = ad[19] + + // masks the byte with 00111111 - AT: Is this a Check if is Xyo Enabled Device? + if (xyoManufactureIdToCreator.containsKey(id and DEVICE_TYPE_MASK)) { + xyoManufactureIdToCreator[id and DEVICE_TYPE_MASK]?.getDevicesFromScanResult(context, scanResult, globalDevices, foundDevices) + return + } else { + log.info("Not an Xyo Device - Not Creating: $hash") + + /* + val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + XyoBluetoothClient(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) + } else { + XyoBluetoothClient(context, scanResult, hash) + } - val ad = scanResult.scanRecord?.getManufacturerSpecificData(0x4c) - - if (ad?.size == 23) { - val id = ad[19] - - // masks the byte with 00111111 - if (xyoManufactureIdToCreator.containsKey(id and DEVICE_TYPE_MASK)) { - xyoManufactureIdToCreator[id and DEVICE_TYPE_MASK]?.getDevicesFromScanResult(context, scanResult, globalDevices, foundDevices) - return + foundDevices[hash] = createdDevice + globalDevices[hash] = createdDevice + */ + } } } - val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - XyoBluetoothClient(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) - } else { - XyoBluetoothClient(context, scanResult, hash) - } - - val foundDevice = foundDevices[hash] - if (foundDevice != null) { - foundDevice.rssi = scanResult.rssi - foundDevice.updateBluetoothDevice(scanResult.device) - } else { - foundDevices[hash] = createdDevice - globalDevices[hash] = createdDevice - } } } } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBridgeX.kt b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBridgeX.kt index 7c96d04..e74a508 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBridgeX.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoBridgeX.kt @@ -34,16 +34,16 @@ open class XyoBridgeX: XyoBluetoothClient { XYBluetoothDevice> ) { val hash = hashFromScanResult(scanResult) - val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - XyoBridgeX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) - } else { - XyoBridgeX(context, scanResult, hash) - } - val foundDevice = foundDevices[hash] - if (foundDevice != null) { - foundDevice.rssi = scanResult.rssi - foundDevice.updateBluetoothDevice(scanResult.device) + val existingDevice = globalDevices[hash] + if (existingDevice != null) { + existingDevice.rssi = scanResult.rssi + existingDevice.updateBluetoothDevice(scanResult.device) } else { + val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + XyoBridgeX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) + } else { + XyoBridgeX(context, scanResult, hash) + } foundDevices[hash] = createdDevice globalDevices[hash] = createdDevice } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoIosAppX.kt b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoIosAppX.kt index 211080b..024be9d 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoIosAppX.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoIosAppX.kt @@ -35,17 +35,16 @@ open class XyoIosAppX : XyoBluetoothClient { ) { val hash = hashFromScanResult(scanResult) - val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - XyoIosAppX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) - } else { - XyoIosAppX(context, scanResult, hash) - } - - val foundDevice = foundDevices[hash] - if (foundDevice != null) { - foundDevice.rssi = scanResult.rssi - foundDevice.updateBluetoothDevice(scanResult.device) + val existingDevice = globalDevices[hash] + if (existingDevice != null) { + existingDevice.rssi = scanResult.rssi + existingDevice.updateBluetoothDevice(scanResult.device) } else { + val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + XyoIosAppX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) + } else { + XyoIosAppX(context, scanResult, hash) + } foundDevices[hash] = createdDevice globalDevices[hash] = createdDevice } diff --git a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoSentinelX.kt b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoSentinelX.kt index 4ffde42..da4627f 100644 --- a/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoSentinelX.kt +++ b/xyo-android-library/src/main/java/network/xyo/sdk/bluetooth/client/XyoSentinelX.kt @@ -206,16 +206,16 @@ open class XyoSentinelX : XyoBluetoothClient { XYBluetoothDevice> ) { val hash = hashFromScanResult(scanResult) - val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - XyoSentinelX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) - } else { - XyoSentinelX(context, scanResult, hash) - } - val foundDevice = foundDevices[hash] - if (foundDevice != null) { - foundDevice.rssi = scanResult.rssi - foundDevice.updateBluetoothDevice(scanResult.device) + val existingDevice = globalDevices[hash] + if (existingDevice != null) { + existingDevice.rssi = scanResult.rssi + existingDevice.updateBluetoothDevice(scanResult.device) } else { + val createdDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + XyoSentinelX(context, scanResult, hash, BluetoothDevice.TRANSPORT_LE) + } else { + XyoSentinelX(context, scanResult, hash) + } foundDevices[hash] = createdDevice globalDevices[hash] = createdDevice } diff --git a/xyo-android-library/version.properties b/xyo-android-library/version.properties index 2fd7f59..046b048 100644 --- a/xyo-android-library/version.properties +++ b/xyo-android-library/version.properties @@ -1,2 +1,2 @@ -#Thu Feb 20 18:46:05 UTC 2020 -VERSION_PATCH=26 +#Tue Feb 25 01:17:07 UTC 2020 +VERSION_PATCH=30 diff --git a/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_client/BleClientFragment.kt b/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_client/BleClientFragment.kt index 97877c9..fb7e074 100644 --- a/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_client/BleClientFragment.kt +++ b/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_client/BleClientFragment.kt @@ -1,5 +1,6 @@ package network.xyo.sdk.sample.ui.ble_client +import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -7,6 +8,9 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_ble_client.* +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import network.xyo.sdk.sample.R import network.xyo.sdk.XyoBleNetwork import network.xyo.sdk.XyoBoundWitnessTarget @@ -18,6 +22,13 @@ import network.xyo.sdkcorekotlin.boundWitness.XyoBoundWitness @kotlin.ExperimentalUnsignedTypes class BleClientFragment : Fragment() { + var deviceCount = 0 + var xyoDeviceCount = 0 + var nearbyXyoDeviceCount = 0 + + var autoUpdateUi = false + var statusText = "" + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -26,40 +37,62 @@ class BleClientFragment : Fragment() { return inflater.inflate(R.layout.fragment_ble_client, container, false) } + override fun onAttach(context: Context) { + super.onAttach(context) + autoUpdateUi = true + GlobalScope.launch { + while(autoUpdateUi) { + this@BleClientFragment.updateUI() + delay(1000) + } + } + } + + override fun onDetach() { + autoUpdateUi = false + super.onDetach() + } + fun addStatus(status: String) { - ui { - text_ble_client?.let { - val sb = StringBuilder() - sb.append(it.text) - sb.append("\r\n") - sb.append(status) - it.text = sb.toString() + statusText = "${statusText}\r\n$status" + text_ble_client?.let { + ui { + it.text = statusText } } } - fun updateUI() { + private fun updateUI() { ui { - (XyoSdk.nodes[0].networks["ble"] as? XyoBleNetwork)?.let { network -> - acceptBridging.isChecked = network.client.acceptBridging - acceptBridging.setOnCheckedChangeListener { _, isChecked -> - network.client.acceptBridging = isChecked - } + if (!(this@BleClientFragment.isDetached)) { + (XyoSdk.nodes[0].networks["ble"] as? XyoBleNetwork)?.let { network -> + acceptBridging?.isChecked = network.client.acceptBridging + acceptBridging?.setOnCheckedChangeListener { _, isChecked -> + network.client.acceptBridging = isChecked + } - autoBoundWitness.isChecked = network.client.autoBoundWitness - autoBoundWitness.setOnCheckedChangeListener { _, isChecked -> - network.client.autoBoundWitness = isChecked - } + autoBoundWitness?.isChecked = network.client.autoBoundWitness + autoBoundWitness?.setOnCheckedChangeListener { _, isChecked -> + network.client.autoBoundWitness = isChecked + } - autoBridge.isChecked = network.client.autoBridge - autoBridge.setOnCheckedChangeListener { _, isChecked -> - network.client.autoBridge = isChecked - } + autoBridge?.isChecked = network.client.autoBridge + autoBridge?.setOnCheckedChangeListener { _, isChecked -> + network.client.autoBridge = isChecked + } + + scan?.isChecked = network.client.scan + scan?.setOnCheckedChangeListener { _, isChecked -> + network.client.scan = isChecked + } - scan.isChecked = network.client.scan - scan.setOnCheckedChangeListener { _, isChecked -> - network.client.scan = isChecked + deviceCount = network.client.deviceCount + xyoDeviceCount = network.client.xyoDeviceCount + nearbyXyoDeviceCount = network.client.nearbyXyoDeviceCount } + detected_devices?.text = deviceCount.toString() + detected_xyo_devices?.text = xyoDeviceCount.toString() + nearby_xyo_devices?.text = nearbyXyoDeviceCount.toString() } } } diff --git a/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_server/BleServerFragment.kt b/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_server/BleServerFragment.kt index 63b12c3..e78237b 100644 --- a/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_server/BleServerFragment.kt +++ b/xyo-android-sample/src/main/java/network/xyo/sdk/sample/ui/ble_server/BleServerFragment.kt @@ -18,14 +18,13 @@ import network.xyo.sdkcorekotlin.boundWitness.XyoBoundWitness @kotlin.ExperimentalUnsignedTypes class BleServerFragment : Fragment() { + var statusText = "" + fun addStatus(status: String) { - ui { - text_ble_server?.let { - val sb = StringBuilder() - sb.append(it.text) - sb.append("\r\n") - sb.append(status) - it.text = sb.toString() + statusText = "${statusText}\r\n$status" + text_ble_server?.let { + ui { + it.text = statusText } } } diff --git a/xyo-android-sample/src/main/res/layout/fragment_ble_client.xml b/xyo-android-sample/src/main/res/layout/fragment_ble_client.xml index 03445ad..1400ab4 100644 --- a/xyo-android-sample/src/main/res/layout/fragment_ble_client.xml +++ b/xyo-android-sample/src/main/res/layout/fragment_ble_client.xml @@ -60,11 +60,66 @@ android:layout_height="wrap_content" android:padding="8dp" android:text="@string/scan"/> + + + + + + + + + + + + + Scan Listen Public Key: + Detected Devices: + Detected XYO Devices: + Nearby XYO Devices: