diff --git a/.editorconfig b/.editorconfig index e86e7585e..9b62cec64 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,7 +15,6 @@ ktlint_standard_chain-method-continuation = disabled ktlint_standard_class-signature = disabled ktlint_standard_function-expression-body = disabled ktlint_standard_function-literal = disabled -ktlint_standard_function-signature = disabled ktlint_standard_max-line-length = disabled ktlint_standard_mixed-condition-operators = disabled ktlint_standard_package-name = disabled diff --git a/app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt b/app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt index 75f5c6195..8b9f6b752 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/testUtil/TrampolineSchedulerRule.kt @@ -17,21 +17,20 @@ class TrampolineSchedulerRule : TestRule { private val scheduler = Schedulers.trampoline() - override fun apply(base: Statement, description: Description): Statement = - object : Statement() { - override fun evaluate() { - try { - RxJavaPlugins.setComputationSchedulerHandler { scheduler } - RxJavaPlugins.setIoSchedulerHandler { scheduler } - RxJavaPlugins.setNewThreadSchedulerHandler { scheduler } - RxJavaPlugins.setSingleSchedulerHandler { scheduler } - RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler } + override fun apply(base: Statement, description: Description): Statement = object : Statement() { + override fun evaluate() { + try { + RxJavaPlugins.setComputationSchedulerHandler { scheduler } + RxJavaPlugins.setIoSchedulerHandler { scheduler } + RxJavaPlugins.setNewThreadSchedulerHandler { scheduler } + RxJavaPlugins.setSingleSchedulerHandler { scheduler } + RxAndroidPlugins.setInitMainThreadSchedulerHandler { scheduler } - base.evaluate() - } finally { - RxJavaPlugins.reset() - RxAndroidPlugins.reset() - } + base.evaluate() + } finally { + RxJavaPlugins.reset() + RxAndroidPlugins.reset() } } + } } diff --git a/app/src/androidTest/java/org/schabi/newpipe/util/StreamItemAdapterTest.kt b/app/src/androidTest/java/org/schabi/newpipe/util/StreamItemAdapterTest.kt index 348612249..22c7887f9 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/util/StreamItemAdapterTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/util/StreamItemAdapterTest.kt @@ -248,39 +248,37 @@ class StreamItemAdapterTest { * @return a list of video streams, in which their video only property mirrors the provided * [videoOnly] vararg. */ - private fun getVideoStreams(vararg videoOnly: Boolean) = - StreamItemAdapter.StreamInfoWrapper( - videoOnly.map { - VideoStream.Builder() - .setId(Stream.ID_UNKNOWN) - .setContent("https://example.com", true) - .setMediaFormat(MediaFormat.MPEG_4) - .setResolution("720p") - .setIsVideoOnly(it) - .build() - }, - context - ) + private fun getVideoStreams(vararg videoOnly: Boolean) = StreamInfoWrapper( + videoOnly.map { + VideoStream.Builder() + .setId(Stream.ID_UNKNOWN) + .setContent("https://example.com", true) + .setMediaFormat(MediaFormat.MPEG_4) + .setResolution("720p") + .setIsVideoOnly(it) + .build() + }, + context + ) /** * @return a list of audio streams, containing valid and null elements mirroring the provided * [shouldBeValid] vararg. */ - private fun getAudioStreams(vararg shouldBeValid: Boolean) = - getSecondaryStreamsFromList( - shouldBeValid.map { - if (it) { - AudioStream.Builder() - .setId(Stream.ID_UNKNOWN) - .setContent("https://example.com", true) - .setMediaFormat(MediaFormat.OPUS) - .setAverageBitrate(192) - .build() - } else { - null - } + private fun getAudioStreams(vararg shouldBeValid: Boolean) = getSecondaryStreamsFromList( + shouldBeValid.map { + if (it) { + AudioStream.Builder() + .setId(Stream.ID_UNKNOWN) + .setContent("https://example.com", true) + .setMediaFormat(MediaFormat.OPUS) + .setAverageBitrate(192) + .build() + } else { + null } - ) + } + ) private fun getIncompleteAudioStreams(size: Int): List { val list = ArrayList(size) @@ -325,18 +323,17 @@ class StreamItemAdapterTest { /** * Helper function that builds a secondary stream list. */ - private fun getSecondaryStreamsFromList(streams: List) = - SparseArrayCompat?>(streams.size).apply { - streams.forEachIndexed { index, stream -> - val secondaryStreamHelper: SecondaryStreamHelper? = stream?.let { - SecondaryStreamHelper( - StreamItemAdapter.StreamInfoWrapper(streams, context), - it - ) - } - put(index, secondaryStreamHelper) + private fun getSecondaryStreamsFromList(streams: List) = SparseArrayCompat?>(streams.size).apply { + streams.forEachIndexed { index, stream -> + val secondaryStreamHelper: SecondaryStreamHelper? = stream?.let { + SecondaryStreamHelper( + StreamItemAdapter.StreamInfoWrapper(streams, context), + it + ) } + put(index, secondaryStreamHelper) } + } private fun getResponse(headers: Map): Response { val listHeaders = HashMap>() diff --git a/app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt b/app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt index 57d47d0ac..816b25c2a 100644 --- a/app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt +++ b/app/src/main/java/org/schabi/newpipe/database/history/model/StreamHistoryEntry.kt @@ -30,16 +30,15 @@ data class StreamHistoryEntry( accessDate.isEqual(other.accessDate) } - fun toStreamInfoItem(): StreamInfoItem = - StreamInfoItem( - streamEntity.serviceId, - streamEntity.url, - streamEntity.title, - streamEntity.streamType - ).apply { - duration = streamEntity.duration - uploaderName = streamEntity.uploader - uploaderUrl = streamEntity.uploaderUrl - thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl) - } + fun toStreamInfoItem(): StreamInfoItem = StreamInfoItem( + streamEntity.serviceId, + streamEntity.url, + streamEntity.title, + streamEntity.streamType + ).apply { + duration = streamEntity.duration + uploaderName = streamEntity.uploader + uploaderUrl = streamEntity.uploaderUrl + thumbnails = ImageStrategy.dbUrlToImageList(streamEntity.thumbnailUrl) + } } diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt index 98cae7b30..05f2b34a9 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorInfo.kt @@ -160,16 +160,14 @@ class ErrorInfo private constructor( const val SERVICE_NONE = "" - private fun getServiceName(serviceId: Int?) = - // not using getNameOfServiceById since we want to accept a nullable serviceId and we + private fun getServiceName(serviceId: Int?) = // not using getNameOfServiceById since we want to accept a nullable serviceId and we // want to default to SERVICE_NONE ServiceList.all().firstOrNull { it.serviceId == serviceId }?.serviceInfo?.name ?: SERVICE_NONE fun throwableToStringList(throwable: Throwable) = arrayOf(throwable.stackTraceToString()) - fun throwableListToStringList(throwableList: List) = - throwableList.map { it.stackTraceToString() }.toTypedArray() + fun throwableListToStringList(throwableList: List) = throwableList.map { it.stackTraceToString() }.toTypedArray() fun getMessage( throwable: Throwable?, diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt index 481846a2b..4e50f7bd1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedViewModel.kt @@ -151,17 +151,14 @@ class FeedViewModel( fun getShowFutureItemsFromPreferences() = getShowFutureItemsFromPreferences(application) companion object { - private fun getShowPlayedItemsFromPreferences(context: Context) = - PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(context.getString(R.string.feed_show_watched_items_key), true) + private fun getShowPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.feed_show_watched_items_key), true) - private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) = - PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true) + private fun getShowPartiallyPlayedItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.feed_show_partially_watched_items_key), true) - private fun getShowFutureItemsFromPreferences(context: Context) = - PreferenceManager.getDefaultSharedPreferences(context) - .getBoolean(context.getString(R.string.feed_show_future_items_key), true) + private fun getShowFutureItemsFromPreferences(context: Context) = PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.feed_show_future_items_key), true) fun getFactory(context: Context, groupId: Long) = viewModelFactory { initializer { diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt index 36be86fcd..d1fd29945 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationWorker.kt @@ -95,9 +95,8 @@ class NotificationWorker( private val TAG = NotificationWorker::class.java.simpleName private const val WORK_TAG = App.PACKAGE_NAME + "_streams_notifications" - private fun areNotificationsEnabled(context: Context) = - NotificationHelper.areNewStreamsNotificationsEnabled(context) && - NotificationHelper.areNotificationsEnabledOnDevice(context) + private fun areNotificationsEnabled(context: Context) = NotificationHelper.areNewStreamsNotificationsEnabled(context) && + NotificationHelper.areNotificationsEnabledOnDevice(context) /** * Schedules a task for the [NotificationWorker] diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt index bc7afe602..2918ad5fb 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionManager.kt @@ -70,19 +70,18 @@ class SubscriptionManager(context: Context) { return listEntities } - fun updateChannelInfo(info: ChannelInfo): Completable = - subscriptionTable.getSubscription(info.serviceId, info.url) - .flatMapCompletable { - Completable.fromRunnable { - it.apply { - name = info.name - avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars) - description = info.description - subscriberCount = info.subscriberCount - } - subscriptionTable.update(it) + fun updateChannelInfo(info: ChannelInfo): Completable = subscriptionTable.getSubscription(info.serviceId, info.url) + .flatMapCompletable { + Completable.fromRunnable { + it.apply { + name = info.name + avatarUrl = ImageStrategy.imageListToDbUrl(info.avatars) + description = info.description + subscriberCount = info.subscriberCount } + subscriptionTable.update(it) } + } fun updateNotificationMode(serviceId: Int, url: String, @NotificationMode mode: Int): Completable { return subscriptionTable().getSubscription(serviceId, url) diff --git a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/PackageValidator.kt b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/PackageValidator.kt index c41f1dadd..05c94e990 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/PackageValidator.kt +++ b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/PackageValidator.kt @@ -173,11 +173,10 @@ internal class PackageValidator(context: Context) { */ @Suppress("deprecation") @SuppressLint("PackageManagerGetSignatures") - private fun getPackageInfo(callingPackage: String): PackageInfo? = - packageManager.getPackageInfo( - callingPackage, - PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS - ) + private fun getPackageInfo(callingPackage: String): PackageInfo? = packageManager.getPackageInfo( + callingPackage, + PackageManager.GET_SIGNATURES or PackageManager.GET_PERMISSIONS + ) /** * Gets the signature of a given package's [PackageInfo]. @@ -189,23 +188,21 @@ internal class PackageValidator(context: Context) { * returns `null` as the signature. */ @Suppress("deprecation") - private fun getSignature(packageInfo: PackageInfo): String? = - if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) { - // Security best practices dictate that an app should be signed with exactly one (1) - // signature. Because of this, if there are multiple signatures, reject it. - null - } else { - val certificate = packageInfo.signatures!![0].toByteArray() - getSignatureSha256(certificate) - } + private fun getSignature(packageInfo: PackageInfo): String? = if (packageInfo.signatures == null || packageInfo.signatures!!.size != 1) { + // Security best practices dictate that an app should be signed with exactly one (1) + // signature. Because of this, if there are multiple signatures, reject it. + null + } else { + val certificate = packageInfo.signatures!![0].toByteArray() + getSignatureSha256(certificate) + } /** * Finds the Android platform signing key signature. This key is never null. */ - private fun getSystemSignature(): String = - getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo -> - getSignature(platformInfo) - } ?: throw IllegalStateException("Platform signature not found") + private fun getSystemSignature(): String = getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo -> + getSignature(platformInfo) + } ?: throw IllegalStateException("Platform signature not found") /** * Creates a SHA-256 signature given a certificate byte array. diff --git a/app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt b/app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt index 9db0e0f59..deeef613a 100644 --- a/app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt +++ b/app/src/main/java/org/schabi/newpipe/util/potoken/PoTokenWebView.kt @@ -179,16 +179,15 @@ class PoTokenWebView private constructor( //endregion //region Obtaining poTokens - override fun generatePoToken(identifier: String): Single = - Single.create { emitter -> - if (BuildConfig.DEBUG) { - Log.d(TAG, "generatePoToken() called with identifier $identifier") - } - runOnMainThread(emitter) { - addPoTokenEmitter(identifier, emitter) - val u8Identifier = stringToU8(identifier) - webView.evaluateJavascript( - """try { + override fun generatePoToken(identifier: String): Single = Single.create { emitter -> + if (BuildConfig.DEBUG) { + Log.d(TAG, "generatePoToken() called with identifier $identifier") + } + runOnMainThread(emitter) { + addPoTokenEmitter(identifier, emitter) + val u8Identifier = stringToU8(identifier) + webView.evaluateJavascript( + """try { identifier = "$identifier" u8Identifier = $u8Identifier poTokenU8 = obtainPoToken(webPoSignalOutput, integrityToken, u8Identifier) @@ -201,9 +200,9 @@ class PoTokenWebView private constructor( } catch (error) { $JS_INTERFACE.onObtainPoTokenError(identifier, error + "\n" + error.stack) }""" - ) {} - } + ) {} } + } /** * Called by the JavaScript snippet from [generatePoToken] when an error occurs in calling the @@ -373,14 +372,13 @@ class PoTokenWebView private constructor( "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.3" private const val JS_INTERFACE = "PoTokenWebView" - override fun newPoTokenGenerator(context: Context): Single = - Single.create { emitter -> - runOnMainThread(emitter) { - val potWv = PoTokenWebView(context, emitter) - potWv.loadHtmlAndObtainBotguard(context) - emitter.setDisposable(potWv.disposables) - } + override fun newPoTokenGenerator(context: Context): Single = Single.create { emitter -> + runOnMainThread(emitter) { + val potWv = PoTokenWebView(context, emitter) + potWv.loadHtmlAndObtainBotguard(context) + emitter.setDisposable(potWv.disposables) } + } /** * Runs [runnable] on the main thread using `Handler(Looper.getMainLooper()).post()`, and