chore: Lint code

This commit is contained in:
inotia00
2025-01-07 14:06:31 +09:00
parent bcc9547b5f
commit a0329d28f5
18 changed files with 100 additions and 54 deletions

View File

@ -30,6 +30,7 @@ object AppClient {
private const val DEVICE_MAKE_IOS = "Apple"
private const val OS_NAME_IOS = "iOS"
/**
* The device machine id for the iPhone 15 Pro Max (iPhone16,2),
* used to get HDR with AV1 hardware decoding.
@ -240,7 +241,6 @@ object AppClient {
val userAgent: String,
/**
* Android SDK version, equivalent to [Build.VERSION.SDK] (System property: ro.build.version.sdk)
* Field is null if not applicable.
*/
val androidSdkVersion: String = Build.VERSION.SDK,
/**

View File

@ -141,6 +141,7 @@ public class SpoofStreamingDataPatch {
* 1. Save the requestHeader in a field.
* 2. Invoke fetchRequest with the videoId used in PlaybackStartDescriptor.
* <p>
*
* @param requestHeaders Save the request Headers used for login to a field.
* Only used in YouTube Music where login is required.
*/

View File

@ -130,17 +130,35 @@ object PlayerRoutes {
}
@JvmStatic
fun getPlayerResponseConnectionFromRoute(route: CompiledRoute, clientType: AppClient.ClientType): HttpURLConnection {
return getPlayerResponseConnectionFromRoute(route, clientType.userAgent, clientType.id.toString())
fun getPlayerResponseConnectionFromRoute(
route: CompiledRoute,
clientType: AppClient.ClientType
): HttpURLConnection {
return getPlayerResponseConnectionFromRoute(
route,
clientType.userAgent,
clientType.id.toString()
)
}
@JvmStatic
fun getPlayerResponseConnectionFromRoute(route: CompiledRoute, clientType: WebClient.ClientType): HttpURLConnection {
return getPlayerResponseConnectionFromRoute(route, clientType.userAgent, clientType.id.toString())
fun getPlayerResponseConnectionFromRoute(
route: CompiledRoute,
clientType: WebClient.ClientType
): HttpURLConnection {
return getPlayerResponseConnectionFromRoute(
route,
clientType.userAgent,
clientType.id.toString()
)
}
@Throws(IOException::class)
fun getPlayerResponseConnectionFromRoute(route: CompiledRoute, userAgent: String, clientVersion: String): HttpURLConnection {
fun getPlayerResponseConnectionFromRoute(
route: CompiledRoute,
userAgent: String,
clientVersion: String
): HttpURLConnection {
val connection = Requester.getConnectionFromCompiledRoute(YT_API_URL, route)
connection.setRequestProperty("Content-Type", "application/json")

View File

@ -9,7 +9,6 @@ import app.revanced.extension.shared.patches.spoof.requests.PlayerRoutes.getPlay
import app.revanced.extension.shared.settings.BaseSettings
import app.revanced.extension.shared.utils.Logger
import app.revanced.extension.shared.utils.Utils
import org.apache.commons.lang3.ArrayUtils
import org.apache.commons.lang3.StringUtils
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
@ -111,6 +110,7 @@ class StreamingDataRequest private constructor(
* Any arbitrarily large value, but must be at least twice [.HTTP_TIMEOUT_MILLISECONDS]
*/
private const val MAX_MILLISECONDS_TO_WAIT_FOR_FETCH = 20 * 1000
@GuardedBy("itself")
val cache: MutableMap<String, StreamingDataRequest> = Collections.synchronizedMap(
object : LinkedHashMap<String, StreamingDataRequest>(100) {
@ -171,11 +171,13 @@ class StreamingDataRequest private constructor(
Logger.printDebug { "Fetching video streams for: $videoId using client: $clientType" }
try {
val connection = getPlayerResponseConnectionFromRoute(GET_STREAMING_DATA, clientType)
val connection =
getPlayerResponseConnectionFromRoute(GET_STREAMING_DATA, clientType)
connection.connectTimeout = HTTP_TIMEOUT_MILLISECONDS
connection.readTimeout = HTTP_TIMEOUT_MILLISECONDS
val usePoToken = clientType.requirePoToken && !StringUtils.isAnyEmpty(botGuardPoToken, visitorId)
val usePoToken =
clientType.requirePoToken && !StringUtils.isAnyEmpty(botGuardPoToken, visitorId)
for (key in REQUEST_HEADER_KEYS) {
var value = playerHeaders[key]
@ -248,7 +250,8 @@ class StreamingDataRequest private constructor(
// Retry with different client if empty response body is received.
for (clientType in CLIENT_ORDER_TO_USE) {
if (clientType.requireAuth &&
playerHeaders[AUTHORIZATION_HEADER] == null) {
playerHeaders[AUTHORIZATION_HEADER] == null
) {
Logger.printDebug { "Skipped login-required client (incognito mode or not logged in)\nClient: $clientType\nVideo: $videoId" }
continue
}
@ -270,7 +273,9 @@ class StreamingDataRequest private constructor(
ByteArrayOutputStream().use { stream ->
val buffer = ByteArray(2048)
var bytesRead: Int
while ((inputStream.read(buffer).also { bytesRead = it }) >= 0) {
while ((inputStream.read(buffer)
.also { bytesRead = it }) >= 0
) {
stream.write(buffer, 0, bytesRead)
}
lastSpoofedClientType = clientType

View File

@ -121,21 +121,27 @@ public class ReturnYouTubeDislikeApi {
public static long getFetchCallResponseTimeLast() {
return fetchCallResponseTimeLast;
}
public static long getFetchCallResponseTimeMin() {
return fetchCallResponseTimeMin;
}
public static long getFetchCallResponseTimeMax() {
return fetchCallResponseTimeMax;
}
public static long getFetchCallResponseTimeAverage() {
return fetchCallCount == 0 ? 0 : (fetchCallResponseTimeTotal / fetchCallCount);
}
public static int getFetchCallCount() {
return fetchCallCount;
}
public static int getFetchCallNumberOfFailures() {
return fetchCallNumberOfFailures;
}
public static int getNumberOfRateLimitRequestsEncountered() {
return numberOfRateLimitRequestsEncountered;
}

View File

@ -19,7 +19,10 @@ import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
class MusicRequest private constructor(private val videoId: String, private val checkCategory: Boolean) {
class MusicRequest private constructor(
private val videoId: String,
private val checkCategory: Boolean
) {
/**
* Time this instance and the fetch future was created.
*/
@ -121,7 +124,10 @@ class MusicRequest private constructor(private val videoId: String, private val
Logger.printDebug { "Fetching playlist request for: $videoId using client: $clientTypeName" }
try {
val connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(PlayerRoutes.GET_PLAYLIST_PAGE, clientType)
val connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(
PlayerRoutes.GET_PLAYLIST_PAGE,
clientType
)
val requestBody =
PlayerRoutes.createApplicationRequestBody(clientType, videoId, "RD$videoId")
@ -158,7 +164,10 @@ class MusicRequest private constructor(private val videoId: String, private val
Logger.printDebug { "Fetching playability request for: $videoId using client: $clientTypeName" }
try {
val connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(PlayerRoutes.GET_CATEGORY, clientType)
val connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(
PlayerRoutes.GET_CATEGORY,
clientType
)
val requestBody =
PlayerRoutes.createWebInnertubeBody(clientType, videoId)

View File

@ -4,7 +4,6 @@ import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.SearchView;

View File

@ -30,7 +30,9 @@ internal class JsonPatchesFileGenerator : PatchesFileGenerator {
},
)
}.let {
patchesJson.writeText(GsonBuilder().serializeNulls().setPrettyPrinting().create().toJson(it))
patchesJson.writeText(
GsonBuilder().serializeNulls().setPrettyPrinting().create().toJson(it)
)
}
}

View File

@ -75,7 +75,8 @@ val albumMusicVideoPatch = bytecodePatch(
audioVideoSwitchToggleConstructorFingerprint.methodOrThrow().apply {
val onClickListenerIndex = indexOfAudioVideoSwitchSetOnClickListenerInstruction(this)
val viewRegister = getInstruction<FiveRegisterInstruction>(onClickListenerIndex).registerC
val viewRegister =
getInstruction<FiveRegisterInstruction>(onClickListenerIndex).registerC
addInstruction(
onClickListenerIndex + 1,
@ -83,11 +84,13 @@ val albumMusicVideoPatch = bytecodePatch(
"$EXTENSION_CLASS_DESCRIPTOR->setAudioVideoSwitchToggleOnLongClickListener(Landroid/view/View;)V"
)
val onClickListenerSyntheticIndex = indexOfFirstInstructionReversedOrThrow(onClickListenerIndex) {
val onClickListenerSyntheticIndex =
indexOfFirstInstructionReversedOrThrow(onClickListenerIndex) {
opcode == Opcode.INVOKE_DIRECT &&
getReference<MethodReference>()?.name == "<init>"
}
val onClickListenerSyntheticClass = (getInstruction<ReferenceInstruction>(onClickListenerSyntheticIndex).reference as MethodReference).definingClass
val onClickListenerSyntheticClass =
(getInstruction<ReferenceInstruction>(onClickListenerSyntheticIndex).reference as MethodReference).definingClass
findMethodOrThrow(onClickListenerSyntheticClass) {
name == "onClick"

View File

@ -5,11 +5,8 @@ import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import com.android.tools.smali.dexlib2.util.MethodUtil
const val GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME = "getGmsCoreVendorGroupId"

View File

@ -1,19 +1,8 @@
package app.revanced.patches.shared.materialyou
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatchContext
import app.revanced.util.copyXmlNode
import app.revanced.util.inputStreamFromBundledResource
import org.w3c.dom.Element
import org.w3c.dom.Node
import java.io.File
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.transform.OutputKeys
import javax.xml.transform.TransformerFactory
import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult
private fun ResourcePatchContext.patchXmlFile(
fromDir: String,

View File

@ -116,15 +116,20 @@ fun baseSpoofStreamingDataPatch(
// region Replace the streaming data.
val approxDurationMsReference = formatStreamModelConstructorFingerprint.matchOrThrow().let {
with (it.method) {
with(it.method) {
getInstruction<ReferenceInstruction>(it.patternMatch!!.startIndex).reference
}
}
val streamingDataFormatsReference = with(videoStreamingDataConstructorFingerprint.methodOrThrow(videoStreamingDataToStringFingerprint)) {
val streamingDataFormatsReference = with(
videoStreamingDataConstructorFingerprint.methodOrThrow(
videoStreamingDataToStringFingerprint
)
) {
val getFormatsFieldIndex = indexOfGetFormatsFieldInstruction(this)
val longMaxValueIndex = indexOfLongMaxValueInstruction(this, getFormatsFieldIndex)
val longMaxValueRegister = getInstruction<OneRegisterInstruction>(longMaxValueIndex).registerA
val longMaxValueRegister =
getInstruction<OneRegisterInstruction>(longMaxValueIndex).registerA
val videoIdIndex =
indexOfFirstInstructionOrThrow(longMaxValueIndex) {
val reference = getReference<FieldReference>()

View File

@ -209,6 +209,10 @@ internal val poTokenToStringFingerprint = legacyFingerprint(
classDef.fields.find { it.type == "[B" } != null &&
// In YouTube, this field's type is 'Lcom/google/android/gms/potokens/PoToken;'.
// In YouTube Music, this class name is obfuscated.
classDef.fields.find { it.accessFlags == AccessFlags.PRIVATE.value && it.type.startsWith("L") } != null
classDef.fields.find {
it.accessFlags == AccessFlags.PRIVATE.value && it.type.startsWith(
"L"
)
} != null
},
)

View File

@ -342,7 +342,8 @@ val toolBarComponentsPatch = bytecodePatch(
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == voiceInputControllerActivityMethodCall
}
val setOnClickListenerIndex = indexOfFirstInstructionOrThrow(voiceInputControllerActivityIndex) {
val setOnClickListenerIndex =
indexOfFirstInstructionOrThrow(voiceInputControllerActivityIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}

View File

@ -271,7 +271,9 @@ val seekbarComponentsPatch = bytecodePatch(
).forEach { method ->
method.apply {
val literalIndex =
indexOfFirstLiteralInstructionOrThrow(launchScreenLayoutTypeLotteFeatureFlag)
indexOfFirstLiteralInstructionOrThrow(
launchScreenLayoutTypeLotteFeatureFlag
)
val resultIndex =
indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT)
val register = getInstruction<OneRegisterInstruction>(resultIndex).registerA

View File

@ -17,7 +17,8 @@ internal val mainActivityBaseContextHook = extensionHook(
attachBaseContextIndex + 1
},
contextRegisterResolver = { method ->
val overrideInstruction = method.implementation!!.instructions.elementAt(attachBaseContextIndex)
val overrideInstruction =
method.implementation!!.instructions.elementAt(attachBaseContextIndex)
as FiveRegisterInstruction
"v${overrideInstruction.registerD}"
},

View File

@ -31,18 +31,21 @@ val fullscreenButtonHookPatch = bytecodePatch(
dependsOn(sharedExtensionPatch)
execute {
val (referenceClass, fullscreenActionClass) = with (nextGenWatchLayoutFullscreenModeFingerprint.methodOrThrow()) {
val (referenceClass, fullscreenActionClass) = with(
nextGenWatchLayoutFullscreenModeFingerprint.methodOrThrow()
) {
val targetIndex = indexOfFirstInstructionReversedOrThrow {
opcode == Opcode.INVOKE_DIRECT &&
getReference<MethodReference>()?.parameterTypes?.size == 2
}
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference
val targetReference =
getInstruction<ReferenceInstruction>(targetIndex).reference as MethodReference
Pair(targetReference.definingClass, targetReference.parameterTypes[1].toString())
}
val (enterFullscreenReference, exitFullscreenReference, opcodeName) =
with (findMethodOrThrow(referenceClass) { parameters == listOf("I") }) {
with(findMethodOrThrow(referenceClass) { parameters == listOf("I") }) {
val enterFullscreenIndex = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
reference?.returnType == "V" &&
@ -62,7 +65,8 @@ val fullscreenButtonHookPatch = bytecodePatch(
getInstruction<ReferenceInstruction>(exitFullscreenIndex).reference
val opcode = getInstruction(enterFullscreenIndex).opcode
val enterFullscreenClass = (enterFullscreenReference as MethodReference).definingClass
val enterFullscreenClass =
(enterFullscreenReference as MethodReference).definingClass
enterFullscreenMethod = if (opcode == Opcode.INVOKE_INTERFACE) {
classes.find { classDef -> classDef.interfaces.contains(enterFullscreenClass) }