Skip to content

Commit

Permalink
Merge pull request #130 from XYOracleNetwork/release
Browse files Browse the repository at this point in the history
Release - Major memory leak fix
  • Loading branch information
Phillip Lorenzo authored Feb 25, 2020
2 parents 1c42929 + 6eb1b76 commit 6e35a77
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 102 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,4 +28,4 @@ jobs:
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: 'develop'
branch: 'release'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 26 additions & 3 deletions xyo-android-library/src/main/java/network/xyo/sdk/XyoBleClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -78,6 +98,7 @@ class XyoBleClient(
return
}
}
nearbyXyoDeviceCount++
GlobalScope.launch {
tryBoundWitnessWithDevice(client)
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions xyo-android-library/version.properties
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 6e35a77

Please sign in to comment.