Skip to content

Commit

Permalink
Merge branch 'in-progress'
Browse files Browse the repository at this point in the history
  • Loading branch information
Woohyeok Choi committed Oct 22, 2020
2 parents 46b9b2e + d2382d9 commit 83fce1e
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 386 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {
minSdkVersion 23
targetSdkVersion 30

versionCode 32
versionName "0.9.9-gamma"
versionCode 33
versionName "0.9.9-delta"
setProperty("archivesBaseName", "$applicationId-v.$versionName")
buildConfigField("Boolean", "GENERATE_DUMMY_ENTITY", "false")
buildConfigField("String", "SERVER_ADDRESS", "\"${rootProject.ext.server_address}\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class ActivityCollector(
recordsUploaded += entities.size
}

override suspend fun list(limit: Long): Collection<PhysicalActivityEntity> = dataRepository.find(0, limit)
override suspend fun list(limit: Long): Collection<PhysicalActivityEntity> =
dataRepository.find(0, limit)

private fun handleActivityRetrieval(intent: Intent) = launch {
if (!ActivityRecognitionResult.hasResult(intent)) return@launch
Expand All @@ -111,7 +112,11 @@ class ActivityCollector(
)
}

put(PhysicalActivityEntity(activities = activities), curTime)
put(
PhysicalActivityEntity(activities = activities).apply {
timestamp = curTime
}
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ class AppUsageCollector(
}
entities.add(entity)
}
putAll(entities)

entities.forEach {
put(it)
}

}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class BatteryCollector(
currentNow = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW),
energyCounter = manager.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER),
technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY) ?: ""
)
put(entity, timestamp)
).apply {
this.timestamp = timestamp
}
put(entity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ class BluetoothCollector(
}

private fun handleDeviceFound(intent: Intent) = launch {
val timestamp = System.currentTimeMillis()
val extras = intent.extras ?: return@launch
val rssi = extras.getShort(BluetoothDevice.EXTRA_RSSI, 0).toInt()
val device = extras.getParcelable<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE)
?: return@launch
val entity = buildEntity(device, rssi, false)

put(entity, timestamp)
val entity = buildEntity(device, rssi, false).apply {
timestamp = System.currentTimeMillis()
}
put(entity)
}

private fun handleLeScanRequest() = launch {
Expand All @@ -190,12 +190,15 @@ class BluetoothCollector(
leScanner.stopScan(scanCallback)
}

val timestamp = System.currentTimeMillis()
putAll(discoveredLeDevices.values, timestamp)
discoveredLeDevices.values.forEach {
put(it)
}
}

private fun handleLeDeviceFound(scanResult: ScanResult) {
discoveredLeDevices[scanResult.device.address] = buildEntity(scanResult.device, scanResult.rssi, true)
discoveredLeDevices[scanResult.device.address] = buildEntity(scanResult.device, scanResult.rssi, true).apply {
timestamp = System.currentTimeMillis()
}
}

private fun buildEntity(device: BluetoothDevice, rssi: Int, isLowEnergy: Boolean) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CallLogCollector(
timestamp = millis
}
}
putAll(entities)
entities.forEach { put(it) }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ class EmbeddedSensorCollector(
10, TimeUnit.SECONDS
).toFlowable(
BackpressureStrategy.BUFFER
).asFlow().collect {
putAll(it)
).asFlow().collect { entities ->
entities.forEach {
put(it)
}
}
}
}
Expand All @@ -106,7 +108,7 @@ class EmbeddedSensorCollector(
override suspend fun list(limit: Long): Collection<EmbeddedSensorEntity> =
dataRepository.find(0, limit)

private fun handleSensorEvent(event: SensorEvent, timestamp: Long) {
private fun handleSensorEvent(event: SensorEvent, timeInMillis: Long) {
val type = event.sensor.type
if (type !in arrayOf(Sensor.TYPE_PROXIMITY, Sensor.TYPE_LIGHT)) return

Expand All @@ -121,8 +123,9 @@ class EmbeddedSensorCollector(
values = listOfNotNull(
event.values.firstOrNull()?.toString()
)
)
entity.timestamp = timestamp
).apply {
timestamp = timeInMillis
}
buffer.onNext(entity)
}

Expand Down
Loading

0 comments on commit 83fce1e

Please sign in to comment.