From e21ae1299bb296451ca921759541469fcead260e Mon Sep 17 00:00:00 2001 From: tzugen Date: Thu, 27 May 2021 11:41:00 +0200 Subject: [PATCH] Fix more detekt and lint issues and remove them from the baseline. --- .../loader/image/AvatarRequestHandler.kt | 4 +- .../loader/image/CoverArtRequestHandler.kt | 4 +- detekt-baseline.xml | 10 --- ultrasonic/lint-baseline.xml | 77 ------------------- .../ultrasonic/activity/NavigationActivity.kt | 2 +- .../fragment/TrackCollectionFragment.kt | 3 +- .../ultrasonic/service/LocalMediaPlayer.kt | 4 +- .../ultrasonic/service/MediaPlayerService.kt | 5 +- .../ultrasonic/service/OfflineMusicService.kt | 4 +- .../ultrasonic/service/RESTMusicService.kt | 2 +- 10 files changed, 11 insertions(+), 104 deletions(-) diff --git a/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/AvatarRequestHandler.kt b/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/AvatarRequestHandler.kt index 9ea19237..ab8ac70e 100644 --- a/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/AvatarRequestHandler.kt +++ b/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/AvatarRequestHandler.kt @@ -26,10 +26,10 @@ class AvatarRequestHandler( ?: throw IllegalArgumentException("Nullable username") val response = apiClient.getAvatar(username) - if (response.hasError()) { + if (response.hasError() || response.stream == null) { throw IOException("${response.apiError}") } else { - return Result(Okio.source(response.stream), Picasso.LoadedFrom.NETWORK) + return Result(Okio.source(response.stream!!), Picasso.LoadedFrom.NETWORK) } } } diff --git a/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/CoverArtRequestHandler.kt b/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/CoverArtRequestHandler.kt index bc1f197a..7e242479 100644 --- a/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/CoverArtRequestHandler.kt +++ b/core/subsonic-api-image-loader/src/main/kotlin/org/moire/ultrasonic/subsonic/loader/image/CoverArtRequestHandler.kt @@ -24,10 +24,10 @@ class CoverArtRequestHandler(private val apiClient: SubsonicAPIClient) : Request ?: throw IllegalArgumentException("Nullable id") val response = apiClient.getCoverArt(id) - if (response.hasError()) { + if (response.hasError() || response.stream == null) { throw IOException("${response.apiError}") } else { - return Result(Okio.source(response.stream), NETWORK) + return Result(Okio.source(response.stream!!), NETWORK) } } } diff --git a/detekt-baseline.xml b/detekt-baseline.xml index 6423c4f4..e1cb4ed7 100644 --- a/detekt-baseline.xml +++ b/detekt-baseline.xml @@ -67,18 +67,10 @@ NestedBlockDepth:DownloadFile.kt$DownloadFile.DownloadTask$override fun execute() NestedBlockDepth:DownloadHandler.kt$DownloadHandler$private fun downloadRecursively( 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 ) NestedBlockDepth:MediaPlayerService.kt$MediaPlayerService$private fun setupOnSongCompletedHandler() - ReturnCount:ActiveServerProvider.kt$ActiveServerProvider$ fun getActiveServer(): ServerSetting ReturnCount:CommunicationErrorHandler.kt$CommunicationErrorHandler.Companion$fun getErrorMessage(error: Throwable, context: Context): String - ReturnCount:FileLoggerTree.kt$FileLoggerTree$ private fun getNextLogFile() - ReturnCount:MediaPlayerService.kt$MediaPlayerService$private fun generateAction(context: Context, requestCode: Int): NotificationCompat.Action? - ReturnCount:RESTMusicService.kt$RESTMusicService$@Throws(Exception::class) override fun getAvatar( username: String?, size: Int, saveToFile: Boolean, highQuality: Boolean ): Bitmap? ReturnCount:RESTMusicService.kt$RESTMusicService$@Throws(Exception::class) override fun getCoverArt( entry: MusicDirectory.Entry?, size: Int, saveToFile: Boolean, highQuality: Boolean ): Bitmap? 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 - 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 @@ -89,7 +81,6 @@ TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer$x: Exception TooGenericExceptionCaught:LocalMediaPlayer.kt$LocalMediaPlayer.PositionCache$e: Exception TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$e: Exception - TooGenericExceptionCaught:MediaPlayerService.kt$MediaPlayerService$x: IndexOutOfBoundsException TooGenericExceptionCaught:SongView.kt$SongView$e: Exception TooGenericExceptionCaught:SubsonicUncaughtExceptionHandler.kt$SubsonicUncaughtExceptionHandler$x: Throwable TooGenericExceptionCaught:VideoPlayer.kt$VideoPlayer$e: Exception @@ -98,7 +89,6 @@ TooManyFunctions:MediaPlayerService.kt$MediaPlayerService : Service TooManyFunctions:RESTMusicService.kt$RESTMusicService : MusicService TooManyFunctions:TrackCollectionFragment.kt$TrackCollectionFragment : Fragment - UnusedPrivateMember:RESTMusicService.kt$RESTMusicService.Companion$private const val INDEXES_FOLDER_STORAGE_NAME = "indexes_folder" UtilityClassWithPublicConstructor:CommunicationErrorHandler.kt$CommunicationErrorHandler UtilityClassWithPublicConstructor:FragmentTitle.kt$FragmentTitle diff --git a/ultrasonic/lint-baseline.xml b/ultrasonic/lint-baseline.xml index c34a884d..21a3f032 100644 --- a/ultrasonic/lint-baseline.xml +++ b/ultrasonic/lint-baseline.xml @@ -23,72 +23,6 @@ column="55"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - val dest: String = try { resources.getResourceName(destination.id) - } catch (e: Resources.NotFoundException) { + } catch (ignored: Resources.NotFoundException) { destination.id.toString() } Timber.d("Navigated to $dest") diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt index 49346615..876bf849 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt @@ -28,7 +28,6 @@ import androidx.lifecycle.Observer import androidx.lifecycle.viewModelScope import androidx.navigation.Navigation import androidx.swiperefreshlayout.widget.SwipeRefreshLayout -import java.security.SecureRandom import java.util.Collections import java.util.Random import kotlinx.coroutines.CoroutineExceptionHandler @@ -92,7 +91,7 @@ class TrackCollectionFragment : Fragment() { private var cancellationToken: CancellationToken? = null private val model: TrackCollectionModel by viewModels() - private val random: Random = SecureRandom() + private val random: Random = Random() override fun onCreate(savedInstanceState: Bundle?) { Util.applyTheme(this.context) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/LocalMediaPlayer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/LocalMediaPlayer.kt index 26b96e36..0e4c2503 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/LocalMediaPlayer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/LocalMediaPlayer.kt @@ -106,7 +106,7 @@ class LocalMediaPlayer( i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.audioSessionId) i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.packageName) context.sendBroadcast(i) - } catch (e: Throwable) { + } catch (ignored: Throwable) { // Froyo or lower } mediaPlayerLooper = Looper.myLooper() @@ -466,7 +466,7 @@ class LocalMediaPlayer( // the equalizer or visualizer with the player try { nextMediaPlayer!!.audioSessionId = mediaPlayer.audioSessionId - } catch (e: Throwable) { + } catch (ignored: Throwable) { } nextMediaPlayer!!.setDataSource(file.path) 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 de935eef..fdc3b4cb 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt @@ -24,7 +24,6 @@ import android.view.KeyEvent import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import org.koin.android.ext.android.inject -import org.koin.core.component.KoinApiExtension import org.moire.ultrasonic.R import org.moire.ultrasonic.activity.NavigationActivity import org.moire.ultrasonic.app.UApp @@ -49,7 +48,6 @@ import timber.log.Timber * Android Foreground Service for playing music * while the rest of the Ultrasonic App is in the background. */ -@KoinApiExtension @Suppress("LargeClass") class MediaPlayerService : Service() { private val binder: IBinder = SimpleServiceBinder(this) @@ -173,8 +171,7 @@ class MediaPlayerService : Service() { fun setCurrentPlaying(currentPlayingIndex: Int) { try { localMediaPlayer.setCurrentPlaying(downloader.downloadList[currentPlayingIndex]) - } catch (x: IndexOutOfBoundsException) { - // Ignored + } catch (ignored: IndexOutOfBoundsException) { } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt index 8766665e..8e751382 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt @@ -15,7 +15,6 @@ import java.io.FileReader import java.io.FileWriter import java.io.InputStream import java.io.Reader -import java.security.SecureRandom import java.util.ArrayList import java.util.HashSet import java.util.LinkedList @@ -45,7 +44,6 @@ import org.moire.ultrasonic.util.FileUtil import org.moire.ultrasonic.util.Util import timber.log.Timber - // TODO: There are quite a number of deeply nested and complicated functions in this class.. // Simplify them :) @Suppress("TooManyFunctions") @@ -290,7 +288,7 @@ class OfflineMusicService : MusicService { if (children.isEmpty()) { return result } - val random: Random = SecureRandom() + val random = Random() for (i in 0 until size) { val file = children[random.nextInt(children.size)] result.addChild(createEntry(file, getName(file))) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt index 28ff9476..fd9f2de6 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt @@ -53,6 +53,7 @@ import timber.log.Timber /** * This Music Service implementation connects to a server using the Subsonic REST API */ +@Suppress("LargeClass") open class RESTMusicService( private val subsonicAPIClient: SubsonicAPIClient, private val fileStorage: PermanentFileStorage, @@ -868,7 +869,6 @@ open class RESTMusicService( companion object { private const val MUSIC_FOLDER_STORAGE_NAME = "music_folder" private const val INDEXES_STORAGE_NAME = "indexes" - private const val INDEXES_FOLDER_STORAGE_NAME = "indexes_folder" private const val ARTISTS_STORAGE_NAME = "artists" } }