Skip to content

Commit 1d60799

Browse files
authored
Code cleanup of detekt issues (#922)
* Code cleanup of detekt issues * spotless
1 parent ba0bb22 commit 1d60799

19 files changed

Lines changed: 41 additions & 137 deletions

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Supported platforms: Android (minimum API level 21)
66

77
- Assemble: `./gradlew assemble`
88
- Run tests: `./gradlew test`
9+
- Run detekt (static analysis): `./gradlew detektDebug`
10+
- Run detekt with baseline: `./gradlew detektRelease`
911
- Install example app: `./gradlew sample-app-compose:installDebug`
1012

1113
## Architecture

config/detekt/detekt.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ config:
44
warningsAsErrors: true
55
excludes: ''
66

7+
empty-blocks:
8+
EmptyFunctionBlock:
9+
ignoreOverridden: true
10+
711
style:
812
active: false
913

@@ -20,4 +24,4 @@ livekit-rules:
2024

2125
exceptions:
2226
TooGenericExceptionCaught:
23-
active: false
27+
active: false

livekit-android-sdk/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protobuf {
9696
}
9797

9898
jacoco {
99-
toolVersion = "0.8.10"
99+
toolVersion = "0.8.14"
100100
}
101101

102102
tasks.withType(Test) {

livekit-android-sdk/detekt-baseline-release.xml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,9 @@
2727
<ID>CyclomaticComplexMethod:Room.kt$Room$@Throws(Exception::class) suspend fun connect(url: String, token: String, options: ConnectOptions = ConnectOptions())</ID>
2828
<ID>CyclomaticComplexMethod:RoomEvent.kt$fun LivekitModels.DisconnectReason?.convert(): DisconnectReason</ID>
2929
<ID>CyclomaticComplexMethod:SignalClient.kt$SignalClient$private fun handleSignalResponseImpl(ws: WebSocket, response: LivekitRtc.SignalResponse)</ID>
30-
<ID>DoubleMutabilityForCollection:CoroutineSdpObserver.kt$CoroutineSdpObserver$private var pendingCreate = mutableListOf&lt;Continuation&lt;Either&lt;SessionDescription, String?>>>()</ID>
31-
<ID>DoubleMutabilityForCollection:CoroutineSdpObserver.kt$CoroutineSdpObserver$private var pendingSets = mutableListOf&lt;Continuation&lt;Either&lt;Unit, String?>>>()</ID>
32-
<ID>DoubleMutabilityForCollection:E2EEManager.kt$E2EEManager$private var frameCryptors = mutableMapOf&lt;Pair&lt;String, Participant.Identity>, FrameCryptor>()</ID>
33-
<ID>DoubleMutabilityForCollection:PeerConnectionTransport.kt$PeerConnectionTransport$private var trackBitrates = mutableMapOf&lt;TrackBitrateInfoKey, TrackBitrateInfo>()</ID>
34-
<ID>DoubleMutabilityForCollection:RegionUrlProvider.kt$RegionUrlProvider$private var attemptedRegions = mutableSetOf&lt;RegionInfo>()</ID>
35-
<ID>DoubleMutabilityForCollection:Room.kt$Room$private var sidToIdentity = mutableMapOf&lt;Participant.Sid, Participant.Identity>()</ID>
36-
<ID>DoubleMutabilityForCollection:Room.kt$Room$private var transcriptionReceivedTimes = mutableMapOf&lt;String, Long>()</ID>
37-
<ID>EmptyCatchBlock:EndpointTokenSource.kt$EndpointTokenSource.&lt;no name provided>${ }</ID>
38-
<ID>EmptyDefaultConstructor:CachingTokenSource.kt$InMemoryTokenStore$()</ID>
39-
<ID>EmptyDefaultConstructor:LocalScreencastVideoTrack.kt$LocalScreencastVideoTrack.MediaProjectionCallback$()</ID>
40-
<ID>EmptyFunctionBlock:CommunicationWorkaround.kt$NoopCommunicationWorkaround${ }</ID>
41-
<ID>EmptyFunctionBlock:LocalVideoTrack.kt$LocalVideoTrack.&lt;no name provided>.&lt;no name provided>${ }</ID>
42-
<ID>EmptyFunctionBlock:NoAudioHandler.kt$NoAudioHandler${ }</ID>
43-
<ID>EmptyFunctionBlock:PublisherTransportObserver.kt$PublisherTransportObserver${ }</ID>
4430
<ID>EmptyFunctionBlock:RTCEngine.kt$RTCEngine${ }</ID>
45-
<ID>EmptyFunctionBlock:Room.kt$Room${ }</ID>
46-
<ID>EmptyFunctionBlock:SubscriberTransportObserver.kt$SubscriberTransportObserver${ }</ID>
47-
<ID>EmptyFunctionBlock:TextureViewRenderer.kt$TextureViewRenderer${}</ID>
48-
<ID>EmptyFunctionBlock:VideoFrameCapturer.kt$VideoFrameCapturer${ }</ID>
4931
<ID>HasPlatformType:DataChannelManager.kt$DataChannelManager$@get:FlowObservable var state by flowDelegate(dataChannel.state()) private set</ID>
50-
<ID>HasPlatformType:RTCModule.kt$RTCModule$@Provides fun sdpFactory()</ID>
5132
<ID>IgnoredReturnValue:BaseStreamReceiver.kt$BaseStreamReceiver$catch { }</ID>
52-
<ID>InjectDispatcher:CoroutinesModule.kt$CoroutinesModule$Default</ID>
53-
<ID>InjectDispatcher:CoroutinesModule.kt$CoroutinesModule$IO</ID>
54-
<ID>InjectDispatcher:CoroutinesModule.kt$CoroutinesModule$Unconfined</ID>
55-
<ID>InjectDispatcher:NetworkMonitor.kt$NetworkMonitor$IO</ID>
5633
<ID>InstanceOfCheckForException:LocalParticipant.kt$LocalParticipant$e is RpcError</ID>
5734
<ID>LargeClass:LocalParticipant.kt$LocalParticipant : ParticipantOutgoingDataStreamManagerRpcManager</ID>
5835
<ID>LargeClass:RTCEngine.kt$RTCEngine : Listener</ID>
@@ -106,14 +83,9 @@
10683
<ID>NestedBlockDepth:RTCEngine.kt$RTCEngine$private fun makeRTCConfig( serverResponse: Either&lt;JoinResponse, ReconnectResponse>, connectOptions: ConnectOptions, ): RTCConfiguration</ID>
10784
<ID>NestedBlockDepth:Room.kt$Room$override suspend fun onPostReconnect(isFullReconnect: Boolean)</ID>
10885
<ID>NestedBlockDepth:SignalClient.kt$SignalClient$override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?)</ID>
109-
<ID>SwallowedException:EndpointTokenSource.kt$EndpointTokenSource.&lt;no name provided>$e: Exception</ID>
11086
<ID>SwallowedException:FlowExt.kt$e: CancellationException</ID>
11187
<ID>SwallowedException:LocalVideoTrack.kt$LocalVideoTrack$e: Exception</ID>
112-
<ID>SwallowedException:NetworkCallbackManager.kt$NetworkCallbackManagerImpl$e: IllegalArgumentException</ID>
113-
<ID>SwallowedException:RemoteParticipant.kt$RemoteParticipant$e: Exception</ID>
11488
<ID>SwallowedException:TextureViewRenderer.kt$TextureViewRenderer$e: NotFoundException</ID>
115-
<ID>ThrowingExceptionsWithoutMessageOrCause:LKDebugTree.kt$LKDebugTree$Throwable()</ID>
116-
<ID>ThrowingExceptionsWithoutMessageOrCause:SignalClient.kt$SignalClient$Exception()</ID>
11789
<ID>TooManyFunctions:CommunicationWorkaround.kt$CommunicationWorkaroundImpl : CommunicationWorkaround</ID>
11890
<ID>TooManyFunctions:E2EEManager.kt$E2EEManager</ID>
11991
<ID>TooManyFunctions:IncomingDataStreamManager.kt$IncomingDataStreamManagerImpl : IncomingDataStreamManager</ID>
@@ -135,17 +107,12 @@
135107
<ID>TooManyFunctions:SimulcastVideoEncoderFactoryWrapper.kt$SimulcastVideoEncoderFactoryWrapper$StreamEncoderWrapper : VideoEncoder</ID>
136108
<ID>TooManyFunctions:SubscriberTransportObserver.kt$SubscriberTransportObserver : ObserverPeerConnectionStateObservable</ID>
137109
<ID>TooManyFunctions:TextureViewRenderer.kt$TextureViewRenderer : TextureViewCallbackSurfaceTextureListenerVideoSinkRendererEventsNotifier</ID>
138-
<ID>UnnecessaryNotNullOperator:E2EEManager.kt$E2EEManager$room!!</ID>
139-
<ID>UnnecessaryNotNullOperator:Room.kt$Room$e2eeManager!!</ID>
140-
<ID>UnnecessarySafeCall:E2EEManager.kt$E2EEManager$(publication.track!! as LocalAudioTrack)?.sender</ID>
141-
<ID>UnnecessarySafeCall:E2EEManager.kt$E2EEManager$(publication.track!! as LocalVideoTrack)?.sender</ID>
142110
<ID>UnsafeCallOnNullableType:AudioSwitchHandler.kt$AudioSwitchHandler$thread!!</ID>
143111
<ID>UnsafeCallOnNullableType:CustomAudioProcessingFactory.kt$CustomAudioProcessingFactory.AudioProcessingBridge$buffer!!</ID>
144112
<ID>UnsafeCallOnNullableType:DataPacketBuffer.kt$DataPacketBuffer$item!!</ID>
145113
<ID>UnsafeCallOnNullableType:E2EEManager.kt$E2EEManager$participant.identity!!</ID>
146114
<ID>UnsafeCallOnNullableType:E2EEManager.kt$E2EEManager$publication.track!!</ID>
147115
<ID>UnsafeCallOnNullableType:E2EEManager.kt$E2EEManager$rtpReceiver!!</ID>
148-
<ID>UnsafeCallOnNullableType:E2EEManager.kt$E2EEManager$rtpSender!!</ID>
149116
<ID>UnsafeCallOnNullableType:E2EEManager.kt$E2EEManager$this.room!!</ID>
150117
<ID>UnsafeCallOnNullableType:EncodingUtils.kt$EncodingUtils$encodings.first().scalabilityMode!!</ID>
151118
<ID>UnsafeCallOnNullableType:LocalParticipant.kt$LocalParticipant$options.backupCodec!!</ID>

livekit-android-sdk/src/main/java/io/livekit/android/dagger/CoroutinesModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 LiveKit, Inc.
2+
* Copyright 2023-2026 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import javax.inject.Named
2525
* @suppress
2626
*/
2727
@Module
28+
@Suppress("InjectDispatcher")
2829
internal object CoroutinesModule {
2930
@Provides
3031
@Named(InjectionNames.DISPATCHER_DEFAULT)

livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ internal object RTCModule {
413413
fun videoHwAccel() = true
414414

415415
@Provides
416-
fun sdpFactory() = SdpFactory.getInstance()
416+
fun sdpFactory(): SdpFactory = SdpFactory.getInstance()
417417
}
418418

419419
/**

livekit-android-sdk/src/main/java/io/livekit/android/e2ee/E2EEManager.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2025 LiveKit, Inc.
2+
* Copyright 2023-2026 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ constructor(
4848
dataPacketCryptorManagerFactory: DataPacketCryptorManager.Factory,
4949
) {
5050
private var room: Room? = null
51-
private var frameCryptors = mutableMapOf<Pair<String, Participant.Identity>, FrameCryptor>()
51+
private val frameCryptors = mutableMapOf<Pair<String, Participant.Identity>, FrameCryptor>()
5252
private var algorithm: FrameCryptorAlgorithm = FrameCryptorAlgorithm.AES_GCM
5353
private lateinit var emitEvent: (roomEvent: RoomEvent) -> Unit?
5454

@@ -116,7 +116,7 @@ constructor(
116116
LKLog.i { "Receiver::onFrameCryptionStateChanged: $trackId, state: $state" }
117117
emitEvent(
118118
RoomEvent.TrackE2EEStateEvent(
119-
room!!,
119+
room,
120120
publication.track!!,
121121
publication,
122122
participant,
@@ -138,15 +138,15 @@ constructor(
138138
}
139139

140140
fun addPublishedTrack(track: Track, publication: TrackPublication, participant: LocalParticipant, room: Room) {
141-
val rtpSender: RtpSender? = when (publication.track!!) {
142-
is LocalAudioTrack -> (publication.track!! as LocalAudioTrack)?.sender
143-
is LocalVideoTrack -> (publication.track!! as LocalVideoTrack)?.sender
141+
val rtpSender: RtpSender = when (publication.track!!) {
142+
is LocalAudioTrack -> (publication.track!! as LocalAudioTrack).sender
143+
is LocalVideoTrack -> (publication.track!! as LocalVideoTrack).sender
144144
else -> {
145145
throw IllegalArgumentException("unsupported track type")
146146
}
147147
} ?: throw IllegalArgumentException("rtpSender is null")
148148

149-
val frameCryptor = addRtpSender(rtpSender!!, participant.identity!!, publication.sid, publication.track!!.kind.name.lowercase())
149+
val frameCryptor = addRtpSender(rtpSender, participant.identity!!, publication.sid, publication.track!!.kind.name.lowercase())
150150
frameCryptor.setObserver { trackId, state ->
151151
LKLog.i { "Sender::onFrameCryptionStateChanged: $trackId, state: $state" }
152152
emitEvent(

livekit-android-sdk/src/main/java/io/livekit/android/room/PeerConnectionTransport.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2025 LiveKit, Inc.
2+
* Copyright 2023-2026 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@ constructor(
9393

9494
private var renegotiate = false
9595

96-
private var trackBitrates = mutableMapOf<TrackBitrateInfoKey, TrackBitrateInfo>()
96+
private val trackBitrates = mutableMapOf<TrackBitrateInfoKey, TrackBitrateInfo>()
9797
private var isClosed = AtomicBoolean(false)
9898

9999
private val latestOfferId = AtomicInteger(0)

livekit-android-sdk/src/main/java/io/livekit/android/room/RegionUrlProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024-2025 LiveKit, Inc.
2+
* Copyright 2024-2026 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ constructor(
4747
private var regionSettings: RegionSettings? = null
4848
private var lastUpdateAt: Long = 0L
4949
private var settingsCacheTimeMs = 30000
50-
private var attemptedRegions = mutableSetOf<RegionInfo>()
50+
private val attemptedRegions = mutableSetOf<RegionInfo>()
5151

5252
fun isLKCloud() = serverUrl.isLKCloud()
5353

livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ constructor(
346346
val serverInfo: ServerInfo?
347347
get() = engine.serverInfo
348348

349-
private var sidToIdentity = mutableMapOf<Participant.Sid, Participant.Identity>()
349+
private val sidToIdentity = mutableMapOf<Participant.Sid, Participant.Identity>()
350350

351351
private var mutableActiveSpeakers by flowDelegate(emptyList<Participant>())
352352

@@ -364,7 +364,7 @@ constructor(
364364
private var regionUrlProvider: RegionUrlProvider? = null
365365
private var regionUrl: String? = null
366366

367-
private var transcriptionReceivedTimes = mutableMapOf<String, Long>()
367+
private val transcriptionReceivedTimes = mutableMapOf<String, Long>()
368368

369369
internal var isPrerecording by defaultsManager::isPrerecording
370370

@@ -1521,9 +1521,7 @@ constructor(
15211521
* @suppress
15221522
*/
15231523
override fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant) {
1524-
e2eeManager?.let { e2eeManager ->
1525-
e2eeManager!!.removePublishedTrack(publication.track!!, publication, participant, this)
1526-
}
1524+
e2eeManager?.removePublishedTrack(publication.track!!, publication, participant, this)
15271525
eventBus.postEvent(RoomEvent.TrackUnpublished(this, publication, participant), coroutineScope)
15281526
}
15291527

@@ -1556,9 +1554,7 @@ constructor(
15561554
publication: RemoteTrackPublication,
15571555
participant: RemoteParticipant,
15581556
) {
1559-
e2eeManager?.let { e2eeManager ->
1560-
e2eeManager!!.removeSubscribedTrack(track, publication, participant, this)
1561-
}
1557+
e2eeManager?.removeSubscribedTrack(track, publication, participant, this)
15621558
eventBus.postEvent(RoomEvent.TrackUnsubscribed(this, track, publication, participant), coroutineScope)
15631559
}
15641560

0 commit comments

Comments
 (0)