diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt index 3377acfc..20923b0b 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt @@ -42,6 +42,7 @@ import retrofit2.Call * Special wrapper for [SubsonicAPIDefinition] that checks if [currentApiVersion] is suitable * for this call. */ +@Suppress("TooManyFunctions") internal class ApiVersionCheckWrapper( val api: SubsonicAPIDefinition, var currentApiVersion: SubsonicAPIVersions diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt index 4455a3b8..fb6ce161 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClient.kt @@ -183,7 +183,7 @@ class SubsonicAPIClient( this.addInterceptor(loggingInterceptor) } - @SuppressWarnings("TrustAllX509TrustManager") + @SuppressWarnings("TrustAllX509TrustManager", "EmptyFunctionBlock") private fun OkHttpClient.Builder.allowSelfSignedCertificates() { val trustManager = object : X509TrustManager { override fun checkClientTrusted(p0: Array?, p1: String?) {} diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt index fbdc27c4..d2717da2 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt @@ -10,6 +10,7 @@ import java.lang.NumberFormatException /** * Subsonic REST API versions. */ +@Suppress("MagicNumber", "ComplexMethod", "ReturnCount", "ThrowsCount") @JsonDeserialize(using = SubsonicAPIVersions.Companion.SubsonicAPIVersionsDeserializer::class) enum class SubsonicAPIVersions(val subsonicVersions: String, val restApiVersion: String) { V1_1_0("3.8", "1.1.0"), diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicError.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicError.kt index ad1419e4..0acc6486 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicError.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicError.kt @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize /** * Common API errors. */ +@Suppress("MagicNumber") @JsonDeserialize(using = SubsonicError.Companion.SubsonicErrorDeserializer::class) sealed class SubsonicError(val code: Int) { data class Generic(val message: String) : SubsonicError(0) diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt index 347e6864..66ba8d8b 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt @@ -63,6 +63,7 @@ class VersionAwareJacksonConverterFactory( } } + @Suppress("SwallowedException") class VersionAwareResponseBodyConverter ( private val notifier: (SubsonicAPIVersions) -> Unit = {}, private val adapter: ObjectReader diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/PasswordExt.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/PasswordExt.kt index 307fc49e..1b449ed1 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/PasswordExt.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/PasswordExt.kt @@ -11,6 +11,7 @@ fun String.toHexBytes(): String = this.toByteArray().toHexBytes() /** * Converts given [ByteArray] to corresponding hex chars representation. */ +@Suppress("MagicNumber") fun ByteArray.toHexBytes(): String { val hexChars = CharArray(this.size * 2) for (j in 0..this.lastIndex) { diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt index 8ab52824..6d58eb0d 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt @@ -38,6 +38,7 @@ enum class AlbumListType(val typeName: String) { else -> throw IllegalArgumentException("Unknown type: $typeName") } + @Suppress("UnusedPrivateMember") // Used in the tests private operator fun String.contains(other: String) = this.equals(other, true) } } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/StreamResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/StreamResponse.kt index 8b4cb060..f1d15aa2 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/StreamResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/StreamResponse.kt @@ -9,6 +9,7 @@ import org.moire.ultrasonic.api.subsonic.SubsonicError * * [responseHttpCode] will be there always. */ +@Suppress("MagicNumber") class StreamResponse( val stream: InputStream? = null, val apiError: SubsonicError? = null, diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 61ee636a..8c0868eb 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -2,66 +2,6 @@ - ComplexMethod:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$@JvmStatic @Throws(IllegalArgumentException::class) fun getClosestKnownClientApiVersion(apiVersion: String): SubsonicAPIVersions - EmptyFunctionBlock:SubsonicAPIClient.kt$SubsonicAPIClient.<no name provided>${} - MagicNumber:PasswordExt.kt$0xFF - MagicNumber:PasswordExt.kt$4 - MagicNumber:PasswordMD5Interceptor.kt$PasswordMD5Interceptor$16 - MagicNumber:StreamResponse.kt$StreamResponse$200 - MagicNumber:StreamResponse.kt$StreamResponse$300 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$10 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$11 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$12 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$13 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$14 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$15 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$16 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$3 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$4 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$5 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$6 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$7 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$8 - MagicNumber:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$9 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$10 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$20 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$30 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$40 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$41 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$50 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$60 - MagicNumber:SubsonicError.kt$SubsonicError.Companion$70 - MagicNumber:SubsonicError.kt$SubsonicError.IncompatibleClientProtocolVersion$20 - MagicNumber:SubsonicError.kt$SubsonicError.IncompatibleServerProtocolVersion$30 - MagicNumber:SubsonicError.kt$SubsonicError.RequestedDataWasNotFound$70 - MagicNumber:SubsonicError.kt$SubsonicError.RequiredParamMissing$10 - MagicNumber:SubsonicError.kt$SubsonicError.TokenAuthNotSupportedForLDAP$41 - MagicNumber:SubsonicError.kt$SubsonicError.TrialPeriodIsOver$60 - MagicNumber:SubsonicError.kt$SubsonicError.UserNotAuthorizedForOperation$50 - MagicNumber:SubsonicError.kt$SubsonicError.WrongUsernameOrPassword$40 - ReturnCount:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$@JvmStatic @Throws(IllegalArgumentException::class) fun getClosestKnownClientApiVersion(apiVersion: String): SubsonicAPIVersions - SwallowedException:VersionAwareJacksonConverterFactory.kt$VersionAwareJacksonConverterFactory.VersionAwareResponseBodyConverter$catch (e: IllegalArgumentException) { // no-op } - ThrowsCount:SubsonicAPIVersions.kt$SubsonicAPIVersions.Companion$@JvmStatic @Throws(IllegalArgumentException::class) fun getClosestKnownClientApiVersion(apiVersion: String): SubsonicAPIVersions - TooManyFunctions:ApiVersionCheckWrapper.kt$ApiVersionCheckWrapper : SubsonicAPIDefinition - UnusedPrivateMember:AlbumListType.kt$AlbumListType.Companion$private operator fun String.contains(other: String) - CommentOverPrivateFunction:EditServerFragment.kt$EditServerFragment$ private fun areFieldsChanged(): Boolean - CommentOverPrivateFunction:EditServerFragment.kt$EditServerFragment$ private fun finishActivity() - CommentOverPrivateFunction:EditServerFragment.kt$EditServerFragment$ private fun getFields(): Boolean - CommentOverPrivateFunction:EditServerFragment.kt$EditServerFragment$ private fun setFields() - CommentOverPrivateFunction:EditServerFragment.kt$EditServerFragment$ private fun testConnection() - CommentOverPrivateFunction:FileLoggerTree.kt$FileLoggerTree$ private fun getNextLogFile() - CommentOverPrivateFunction:FileLoggerTree.kt$FileLoggerTree$ private fun getNumberedFile(next: Boolean) - CommentOverPrivateFunction:MediaPlayerService.kt$MediaPlayerService$ private fun buildForegroundNotification( playerState: PlayerState, currentPlaying: DownloadFile? ): Notification - CommentOverPrivateFunction:RESTMusicService.kt$RESTMusicService$ @Throws(Exception::class) private fun search2( criteria: SearchCriteria ): SearchResult - CommentOverPrivateFunction:RESTMusicService.kt$RESTMusicService$ @Throws(Exception::class) private fun searchOld( criteria: SearchCriteria ): SearchResult - CommentOverPrivateFunction:ServerRowAdapter.kt$ServerRowAdapter$ private fun popupMenuItemClick(menuItem: MenuItem, position: Int): Boolean - CommentOverPrivateFunction:ServerRowAdapter.kt$ServerRowAdapter$ private fun serverMenuClick(view: View, position: Int) - CommentOverPrivateFunction:ServerSelectorFragment.kt$ServerSelectorFragment$ private fun editServer(index: Int) - CommentOverPrivateFunction:ServerSelectorFragment.kt$ServerSelectorFragment$ private fun onServerDeleted(index: Int) - CommentOverPrivateFunction:ServerSelectorFragment.kt$ServerSelectorFragment$ private fun setActiveServer(index: Int) - CommentOverPrivateFunction:ServerSettingsModel.kt$ServerSettingsModel$ private fun loadServerSettingFromPreferences( preferenceId: Int, serverId: Int, settings: SharedPreferences ): ServerSetting? - CommentOverPrivateFunction:ServerSettingsModel.kt$ServerSettingsModel$ private suspend fun areIndexesMissing(): Boolean - CommentOverPrivateFunction:ServerSettingsModel.kt$ServerSettingsModel$ private suspend fun reindexSettings() ComplexCondition:DownloadHandler.kt$DownloadHandler.<no name provided>$!append && !playNext && !unpin && !background ComplexCondition:FilePickerAdapter.kt$FilePickerAdapter$currentDirectory.absolutePath == "/" || currentDirectory.absolutePath == "/storage" || currentDirectory.absolutePath == "/storage/emulated" || currentDirectory.absolutePath == "/mnt" ComplexCondition:LocalMediaPlayer.kt$LocalMediaPlayer$Util.getGaplessPlaybackPreference() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ( playerState === PlayerState.STARTED || playerState === PlayerState.PAUSED ) @@ -89,7 +29,6 @@ ImplicitDefaultLocale:SongView.kt$SongView$String.format("%02d.", trackNumber) ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s ", bitRate) ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s > %s", suffix, transcodedSuffix) - LargeClass:MediaPlayerService.kt$MediaPlayerService : Service LargeClass:RESTMusicService.kt$RESTMusicService : MusicService LargeClass:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment LongMethod:DownloadFile.kt$DownloadFile.DownloadTask$override fun execute() @@ -104,25 +43,11 @@ LongMethod:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onViewCreated(view: View, savedInstanceState: Bundle?) LongMethod:TrackCollectionFragment.kt$TrackCollectionFragment$private fun updateDisplay(refresh: Boolean) LongMethod:TrackCollectionFragment.kt$TrackCollectionFragment$private fun updateInterfaceWithEntries(musicDirectory: MusicDirectory) - LongParameterList:DownloadHandler.kt$DownloadHandler$( fragment: Fragment, append: Boolean, save: Boolean, autoPlay: Boolean, playNext: Boolean, shuffle: Boolean, songs: List<MusicDirectory.Entry?> ) - LongParameterList:DownloadHandler.kt$DownloadHandler$( fragment: Fragment, id: String, name: String?, isShare: Boolean, isDirectory: Boolean, save: Boolean, append: Boolean, autoPlay: Boolean, shuffle: Boolean, background: Boolean, playNext: Boolean, unpin: Boolean, isArtist: Boolean ) - LongParameterList:DownloadHandler.kt$DownloadHandler$( fragment: Fragment, id: String, name: String?, save: Boolean, append: Boolean, autoplay: Boolean, shuffle: Boolean, background: Boolean, playNext: Boolean, unpin: Boolean ) - LongParameterList:DownloadHandler.kt$DownloadHandler$( fragment: Fragment, id: String?, save: Boolean, append: Boolean, autoPlay: Boolean, shuffle: Boolean, background: Boolean, playNext: Boolean, unpin: Boolean, isArtist: Boolean ) LongParameterList:ServerRowAdapter.kt$ServerRowAdapter$( private var context: Context, private var data: Array<ServerSetting>, private val model: ServerSettingsModel, private val activeServerProvider: ActiveServerProvider, private val manageMode: Boolean, private val serverDeletedCallback: ((Int) -> Unit), private val serverEditRequestedCallback: ((Int) -> Unit) ) MagicNumber:ActiveServerProvider.kt$ActiveServerProvider$8192 - MagicNumber:AudioFocusHandler.kt$AudioFocusHandler$0.1f - MagicNumber:DownloadFile.kt$DownloadFile$100 MagicNumber:DownloadFile.kt$DownloadFile.DownloadTask$10 MagicNumber:DownloadFile.kt$DownloadFile.DownloadTask$1000L MagicNumber:DownloadFile.kt$DownloadFile.DownloadTask$60 - MagicNumber:DownloadHandler.kt$DownloadHandler$500 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$100 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$3 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$4 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$5 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$6 - MagicNumber:FileLoggerTree.kt$FileLoggerTree$7 - MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer$100 MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer$1000 MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.<no name provided>$1000 MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.<no name provided>$60000 @@ -134,13 +59,10 @@ MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$8L MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.CheckCompletionTask$5000L MagicNumber:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$50L - MagicNumber:MediaPlayerService.kt$MediaPlayerService$100 MagicNumber:MediaPlayerService.kt$MediaPlayerService$1000 MagicNumber:MediaPlayerService.kt$MediaPlayerService$256 MagicNumber:MediaPlayerService.kt$MediaPlayerService$3 MagicNumber:MediaPlayerService.kt$MediaPlayerService$4 - MagicNumber:MediaPlayerService.kt$MediaPlayerService.Companion$19 - MagicNumber:MediaPlayerService.kt$MediaPlayerService.Companion$50L MagicNumber:RESTMusicService.kt$RESTMusicService$206 MagicNumber:RESTMusicService.kt$RESTMusicService$5 MagicNumber:SongView.kt$SongView$3 @@ -159,16 +81,12 @@ ReturnCount:ServerRowAdapter.kt$ServerRowAdapter$ private fun popupMenuItemClick(menuItem: MenuItem, position: Int): Boolean ReturnCount:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onContextItemSelected(menuItem: MenuItem): Boolean ReturnCount:TrackCollectionFragment.kt$TrackCollectionFragment$override fun onOptionsItemSelected(item: MenuItem): Boolean - SpreadOperator:MediaPlayerService.kt$MediaPlayerService$(*compactActions) - SwallowedException:DownloadFile.kt$DownloadFile$catch (e: Exception) { Timber.w("Failed to set last-modified date on %s", file) } - SwallowedException:DownloadFile.kt$DownloadFile$catch (ex: IOException) { Timber.w("Failed to rename file %s to %s", completeFile, saveFile) } SwallowedException:LocalMediaPlayer.kt$LocalMediaPlayer$catch (e: Throwable) { // Froyo or lower } SwallowedException:LocalMediaPlayer.kt$LocalMediaPlayer$catch (e: Throwable) { } SwallowedException:MediaPlayerService.kt$MediaPlayerService$catch (x: IndexOutOfBoundsException) { // Ignored } SwallowedException:NavigationActivity.kt$NavigationActivity$catch (e: Resources.NotFoundException) { destination.id.toString() } ThrowsCount:ApiCallResponseChecker.kt$ApiCallResponseChecker.Companion$@Throws(SubsonicRESTException::class, IOException::class) fun checkResponseSuccessful(response: Response<out SubsonicResponse>) TooGenericExceptionCaught:DownloadFile.kt$DownloadFile$e: Exception - TooGenericExceptionCaught:DownloadFile.kt$DownloadFile.DownloadTask$x: Exception TooGenericExceptionCaught:FileLoggerTree.kt$FileLoggerTree$x: Throwable TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$e: Throwable TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$ex: Exception @@ -185,10 +103,8 @@ TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment - TopLevelPropertyNaming:SubsonicUncaughtExceptionHandler.kt$private const val filename = "ultrasonic-stacktrace.txt" UnusedPrivateMember:RESTMusicService.kt$RESTMusicService.Companion$private const val INDEXES_FOLDER_STORAGE_NAME = "indexes_folder" UtilityClassWithPublicConstructor:CommunicationErrorHandler.kt$CommunicationErrorHandler UtilityClassWithPublicConstructor:FragmentTitle.kt$FragmentTitle - UnnecessaryAbstractClass:BaseStorageTest.kt$BaseStorageTest diff --git a/detekt-config.yml b/detekt-config.yml index f152b9ec..6b7db639 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -62,13 +62,15 @@ style: maxLineLength: 120 excludePackageStatements: false excludeImportStatements: false + MagicNumber: + ignoreNumbers: ['-1', '0', '1', '2', '100'] + ignoreEnums: true + ignorePropertyDeclaration: true + UnnecessaryAbstractClass: + active: false comments: active: true - CommentOverPrivateFunction: - active: true - CommentOverPrivateProperty: - active: true UndocumentedPublicClass: active: false searchInNestedClass: true diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/log/FileLoggerTree.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/log/FileLoggerTree.kt index 0aa2362f..c6b701e9 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/log/FileLoggerTree.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/log/FileLoggerTree.kt @@ -13,6 +13,7 @@ import timber.log.Timber * A Timber Tree which can be used to log to a file * Subclass of the DebugTree so it inherits the Tag handling */ +@Suppress("MagicNumber") class FileLoggerTree : Timber.DebugTree() { private val dateFormat = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt index 1a70cd77..3ccdd06c 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt @@ -19,6 +19,7 @@ import java.io.IOException import java.io.InputStream import java.io.OutputStream import java.io.RandomAccessFile +import org.koin.core.component.KoinApiExtension import org.koin.java.KoinJavaComponent.inject import org.moire.ultrasonic.domain.MusicDirectory import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService @@ -34,6 +35,7 @@ import timber.log.Timber * @author Sindre Mehus * @version $Id$ */ +@KoinApiExtension class DownloadFile( private val context: Context, val song: MusicDirectory.Entry, @@ -190,8 +192,8 @@ class DownloadFile( } completeWhenDone = false } - } catch (ex: IOException) { - Timber.w("Failed to rename file %s to %s", completeFile, saveFile) + } catch (e: IOException) { + Timber.w(e, "Failed to rename file %s to %s", completeFile, saveFile) } } @@ -199,6 +201,8 @@ class DownloadFile( return String.format("DownloadFile (%s)", song) } + @KoinApiExtension + @Suppress("TooGenericExceptionCaught") private inner class DownloadTask : CancellableTask() { override fun execute() { var inputStream: InputStream? = null @@ -286,7 +290,7 @@ class DownloadFile( Util.renameFile(partialFile, completeFile) } } - } catch (x: Exception) { + } catch (e: Exception) { Util.close(outputStream) Util.delete(completeFile) Util.delete(saveFile) @@ -295,7 +299,7 @@ class DownloadFile( if (retryCount > 0) { --retryCount } - Timber.w(x, "Failed to download '%s'.", song) + Timber.w(e, "Failed to download '%s'.", song) } } finally { Util.close(inputStream) @@ -332,8 +336,8 @@ class DownloadFile( val size = Util.getMinDisplayMetric(context) musicService.getCoverArt(song, size, true, true) } - } catch (x: Exception) { - Timber.e(x, "Failed to get cover art.") + } catch (e: Exception) { + Timber.e(e, "Failed to get cover art.") } } @@ -376,7 +380,7 @@ class DownloadFile( raf.setLength(length) raf.close() } catch (e: Exception) { - Timber.w("Failed to set last-modified date on %s", file) + Timber.w(e, "Failed to set last-modified date on %s", file) } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt index 1d7bda38..325ecf0a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt @@ -47,6 +47,7 @@ import timber.log.Timber * Android Foreground Service for playing music * while the rest of the Ultrasonic App is in the background. */ +@Suppress("LargeClass") class MediaPlayerService : Service() { private val binder: IBinder = SimpleServiceBinder(this) private val scrobbler = Scrobbler() @@ -596,6 +597,7 @@ class MediaPlayerService : Service() { /** * This method builds a notification, reusing the Notification Builder if possible */ + @Suppress("SpreadOperator") private fun buildForegroundNotification( playerState: PlayerState, currentPlaying: DownloadFile? @@ -893,6 +895,7 @@ class MediaPlayerService : Service() { mediaSession?.setMediaButtonReceiver(null) } + @Suppress("MagicNumber") companion object { private const val NOTIFICATION_CHANNEL_ID = "org.moire.ultrasonic" private const val NOTIFICATION_CHANNEL_NAME = "Ultrasonic background service" diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt index ac1f8c6c..487e552a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt @@ -19,6 +19,7 @@ import org.moire.ultrasonic.util.Util /** * Retrieves a list of songs and adds them to the now playing list */ +@Suppress("LongParameterList") @KoinApiExtension class DownloadHandler( val mediaPlayerController: MediaPlayerController, diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SubsonicUncaughtExceptionHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SubsonicUncaughtExceptionHandler.kt index 7e7fab3e..5a5d77cf 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SubsonicUncaughtExceptionHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SubsonicUncaughtExceptionHandler.kt @@ -6,8 +6,6 @@ import java.io.File import java.io.PrintWriter import timber.log.Timber -private const val filename = "ultrasonic-stacktrace.txt" - /** * Logs the stack trace of uncaught exceptions to a file on the SD card. */ @@ -22,7 +20,7 @@ class SubsonicUncaughtExceptionHandler( var printWriter: PrintWriter? = null try { - file = File(FileUtil.getUltrasonicDirectory(), filename) + file = File(FileUtil.getUltrasonicDirectory(), STACKTRACE_NAME) printWriter = PrintWriter(file) val logMessage = String.format( "Android API level: %s\nUltrasonic version name: %s\n" + @@ -40,4 +38,8 @@ class SubsonicUncaughtExceptionHandler( defaultHandler?.uncaughtException(thread, throwable) } } + + companion object { + private const val STACKTRACE_NAME = "ultrasonic-stacktrace.txt" + } }