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