Skip to content

Commit

Permalink
v 0.3
Browse files Browse the repository at this point in the history
* Feature/capture
* Test/add tests
* update deps
* change new tyres color
* add system time view
  • Loading branch information
sedmess authored Jul 6, 2021
1 parent 7f9ac19 commit 3aae919
Show file tree
Hide file tree
Showing 26 changed files with 981 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

21 changes: 8 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'org.jetbrains.kotlin.kapt'
}

android {
Expand All @@ -13,7 +12,7 @@ android {
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
versionName "0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -30,7 +29,6 @@ android {
}
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs = ['-Xjvm-default=enable']
}
lintOptions {
abortOnError false
Expand All @@ -43,19 +41,16 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

implementation "ch.acra:acra-core:$acra_version"
implementation("ch.acra:acra-toast:$acra_version")
implementation("ch.acra:acra-dialog:$acra_version")

compileOnly("com.google.auto.service:auto-service-annotations:1.0")
kapt("com.google.auto.service:auto-service:1.0")
implementation 'cat.ereza:customactivityoncrash:2.3.0'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'org.mockito:mockito-core:3.11.2'
testImplementation "org.robolectric:robolectric:4.5.1"
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
android:enabled="true"
android:exported="false" />

<service android:name=".ReplayService"
android:enabled="true"
android:exported="false" />

<activity
android:name=".MainActivity"
android:screenOrientation="sensorLandscape">
Expand All @@ -35,7 +39,7 @@
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:process=":acra" />
android:process=":reporting" />

</application>

Expand Down
21 changes: 4 additions & 17 deletions app/src/main/java/ru/n1ks/f1dashboard/DashboardApplication.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
package ru.n1ks.f1dashboard

import android.app.Application
import android.content.Context
import org.acra.config.dialog
import org.acra.data.StringFormat
import org.acra.ktx.initAcra
import ru.n1ks.f1dashboard.reporting.CrashReportActivity
import ru.n1ks.f1dashboard.reporting.initReporting

class DashboardApplication : Application() {

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
override fun onCreate() {
super.onCreate()

initAcra {
//core configuration:
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.JSON

dialog {
//allows other customization
reportDialogClass = CrashReportActivity::class.java
}
}
initReporting(this)
}
}
111 changes: 60 additions & 51 deletions app/src/main/java/ru/n1ks/f1dashboard/ListenerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,81 @@ package ru.n1ks.f1dashboard
import android.app.*
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import android.util.Log
import io.reactivex.BackpressureStrategy
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers
import ru.n1ks.f1dashboard.model.TelemetryData
import ru.n1ks.f1dashboard.model.TelemetryPacket
import ru.n1ks.f1dashboard.model.TelemetryPacketDeserializer
import ru.n1ks.f1dashboard.Properties.Companion.loadProperties
import ru.n1ks.f1dashboard.capture.LiveCaptureWorker
import ru.n1ks.f1dashboard.capture.Recorder
import ru.n1ks.f1dashboard.reporting.PacketTail
import java.io.File
import java.net.*
import java.nio.ByteBuffer
import java.util.*
import java.util.concurrent.atomic.AtomicLong


class ListenerService : Service() {
class ListenerService : TelemetryProviderService(), Recorder {

companion object {

private const val TAG = "ListenerService"

private const val UDPBufferLength = 2048
private const val DroppedReportInterval = 10000

fun bindService(context: Context, properties: Properties, connection: ServiceConnection) {
val intent = Intent(context, ListenerService::class.java)
intent.apply {
putExtra(Properties.Port, properties.port)
}
context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
}

fun unbindService(context: Context, connection: ServiceConnection) =
context.unbindService(connection)
}

inner class Binder : android.os.Binder() {

fun flow() = this@ListenerService.messageFlow!!
}

private val binder = Binder()
private var socket: DatagramSocket? = null
private var messageFlow: Flowable<TelemetryPacket<out TelemetryData>>? = null
private var messageFlow: Flowable<ByteArray>? = null

override fun onBind(intent: Intent): IBinder {
Log.d(TAG, "start")
val port = intent.getIntExtra(Properties.Port, -1)
@Volatile
private var liveCaptureWorker: LiveCaptureWorker? = null

override fun start(intent: Intent) {
val port = getSharedPreferences(Properties.Name, Context.MODE_PRIVATE).loadProperties().port
initServer(port)

return binder
}

override fun onUnbind(intent: Intent?): Boolean {
Log.d(TAG, "stopping")

override fun stop() {
closeSocket()


synchronized(this) {
if (liveCaptureWorker != null) {
stopRecording()
}
}

socket = null
messageFlow = null

return false
}

override fun onDestroy() {
Log.d(TAG, "destroy")
super.onDestroy()
override fun startRecording() {
synchronized(this) {
if (liveCaptureWorker != null) {
startRecording()
}
val captureFile = File(this.filesDir, Recorder.LastestCaptureFilename)
liveCaptureWorker = LiveCaptureWorker(captureFile)
Log.d(TAG, "start capturing to file: " + captureFile.absolutePath)
}
}

closeSocket()
socket = null
messageFlow = null
override fun stopRecording(): Long {
synchronized(this) {
val frameCount = liveCaptureWorker?.let {
Log.d(TAG, "stop capturing")
val frameCount = it.frameCount
it.close()
frameCount
} ?: 0
liveCaptureWorker = null
return frameCount
}
}

override fun flow(): Flowable<ByteArray> = messageFlow ?: throw IllegalStateException("service not initialized")

private fun initServer(port: Int) {
socket = DatagramSocket(port)
val droppedLastTimestamp = AtomicLong()
val droppedCounter = AtomicLong()
messageFlow = Flowable.create<DatagramPacket>(
messageFlow = Flowable.create<ByteArray>(
{
droppedLastTimestamp.set(System.currentTimeMillis())
while (!it.isCancelled) {
Expand All @@ -96,7 +92,8 @@ class ListenerService : Service() {
it.onError(e)
break
}
it.onNext(packet)
packet.data
it.onNext(packet.data.copyOf(packet.length))
}
it.onComplete()
},
Expand All @@ -108,7 +105,10 @@ class ListenerService : Service() {
synchronized(droppedLastTimestamp) {
val period = System.currentTimeMillis() - droppedLastTimestamp.get()
if (period > DroppedReportInterval) {
Log.i(TAG, "dropped ${droppedCounter.incrementAndGet()} in last $period ms")
Log.i(
TAG,
"dropped ${droppedCounter.incrementAndGet()} in last $period ms"
)
droppedLastTimestamp.set(System.currentTimeMillis())
droppedCounter.set(0)
return@onBackpressureDrop
Expand All @@ -117,8 +117,17 @@ class ListenerService : Service() {
}
droppedCounter.incrementAndGet()
}
.doOnTerminate { closeSocket() }
.map { TelemetryPacketDeserializer.map(ByteBuffer.wrap(it.data)) }
.doFinally { closeSocket() }
.doOnNext {
PacketTail.onPacket(it)
if (liveCaptureWorker != null) {
synchronized(this) {
if (liveCaptureWorker != null) {
liveCaptureWorker!!.onPacket(it)
}
}
}
}
}

private fun closeSocket() {
Expand Down
Loading

0 comments on commit 3aae919

Please sign in to comment.