Skip to content

Commit

Permalink
chore: Lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and anddea committed Jan 10, 2025
1 parent e1093a1 commit 55b28b4
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ public static boolean fixHLSCurrentTime(boolean original) {
* 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.
*
* @param requestHeaders Save the request Headers used for login to a field.
* Only used in YouTube Music where login is required.
*/
private static void setRequestHeaders(Map<String, String> requestHeaders) {
if (SPOOF_STREAMING_DATA_MUSIC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ public static boolean ImageSearchButton() {
return false;
}

public static boolean MinimalHeader() {
// Replace this with true If the Custom header patch succeeds and the patch option was `youtube_minimal_header`
return false;
}

public static boolean PlayerButtons() {
// Replace this with true if the Hide player buttons patch succeeds
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static void initializeReVancedSettings() {
enableDisablePreferences();

AmbientModePreferenceLinks();
ChangeHeaderPreferenceLinks();
ExternalDownloaderPreferenceLinks();
FullScreenPanelPreferenceLinks();
MiniPlayerPreferenceLinks();
Expand All @@ -70,16 +69,6 @@ private static void AmbientModePreferenceLinks() {
);
}

/**
* Enable/Disable Preference related to Change header
*/
private static void ChangeHeaderPreferenceLinks() {
enableDisablePreferences(
PatchStatus.MinimalHeader(),
Settings.CHANGE_YOUTUBE_HEADER
);
}

/**
* Enable/Disable Preference for External downloader settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,22 @@ 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,
"invoke-static { v$viewRegister }, " +
"$EXTENSION_CLASS_DESCRIPTOR->setAudioVideoSwitchToggleOnLongClickListener(Landroid/view/View;)V"
)

val onClickListenerSyntheticIndex = indexOfFirstInstructionReversedOrThrow(onClickListenerIndex) {
opcode == Opcode.INVOKE_DIRECT &&
getReference<MethodReference>()?.name == "<init>"
}
val onClickListenerSyntheticClass = (getInstruction<ReferenceInstruction>(onClickListenerSyntheticIndex).reference as MethodReference).definingClass
val onClickListenerSyntheticIndex =
indexOfFirstInstructionReversedOrThrow(onClickListenerIndex) {
opcode == Opcode.INVOKE_DIRECT &&
getReference<MethodReference>()?.name == "<init>"
}
val onClickListenerSyntheticClass =
(getInstruction<ReferenceInstruction>(onClickListenerSyntheticIndex).reference as MethodReference).definingClass

findMethodOrThrow(onClickListenerSyntheticClass) {
name == "onClick"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,11 @@ val toolBarComponentsPatch = bytecodePatch(
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == voiceInputControllerActivityMethodCall
}
val setOnClickListenerIndex = indexOfFirstInstructionOrThrow(voiceInputControllerActivityIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val setOnClickListenerIndex =
indexOfFirstInstructionOrThrow(voiceInputControllerActivityIndex) {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.name == "setOnClickListener"
}
val viewRegister =
getInstruction<FiveRegisterInstruction>(setOnClickListenerIndex).registerC

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ val overlayButtonsPatch = resourcePatch(
)

val isButton = if (is_19_17_or_greater)
// Note: Do not modify fullscreen button and multiview button
// Note: Do not modify fullscreen button and multiview button
id.endsWith("_button") && id != "@id/multiview_button"
else
id.endsWith("_button") || id == "@id/youtube_controls_fullscreen_button_stub"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ internal val mainActivityBaseContextHook = extensionHook(
attachBaseContextIndex + 1
},
contextRegisterResolver = { method ->
val overrideInstruction = method.implementation!!.instructions.elementAt(attachBaseContextIndex)
as FiveRegisterInstruction
val overrideInstruction =
method.implementation!!.instructions.elementAt(attachBaseContextIndex)
as FiveRegisterInstruction
"v${overrideInstruction.registerD}"
},
) {
Expand Down
Loading

0 comments on commit 55b28b4

Please sign in to comment.