Skip to content

Commit

Permalink
feat(YouTube Music - Hide action bar components): Limit the available…
Browse files Browse the repository at this point in the history
… versions of the `Override Download action button` setting to 7.16.53
  • Loading branch information
inotia00 authored and anddea committed Dec 21, 2024
1 parent 10e4667 commit 16ead35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import androidx.annotation.NonNull;

import java.util.Map;

import app.revanced.extension.music.settings.Settings;
import app.revanced.extension.music.utils.VideoUtils;

@SuppressWarnings("unused")
public class ActionBarPatch {
Expand Down Expand Up @@ -42,41 +39,6 @@ public static void hideLikeDislikeButton(View view) {
);
}

private static final String senderView = "com.google.android.libraries.youtube.rendering.elements.sender_view";

public static boolean inAppDownloadButtonOnClick(Map mMap) {
if (!Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get()) {
return false;
}
if (mMap == null || mMap.isEmpty()) {
return false;
}
if (!mMap.containsKey(senderView)) {
return false;
}
if (!(getLithoViewFromMap(mMap, senderView, View.class) instanceof View view)) {
return false;
}
VideoUtils.launchExternalDownloader();
return true;
}

/**
* Rest of the implementation added by patch.
*/
private static Object getLithoViewFromMap(Map mMap, Object mObject, Class<?> mClass) {
return null;
}

public static void inAppDownloadButtonOnClick(View view) {
if (!Settings.EXTERNAL_DOWNLOADER_ACTION_BUTTON.get()) {
return;
}

if (buttonType.equals(ActionButton.DOWNLOAD.name))
view.setOnClickListener(imageView -> VideoUtils.launchExternalDownloader());
}

public static void setButtonType(@NonNull Object obj) {
final String buttonType = obj.toString();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.revanced.patches.music.actionbar.components

import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
Expand All @@ -24,7 +23,6 @@ import app.revanced.patches.music.utils.settings.settingsPatch
import app.revanced.patches.music.video.information.videoInformationPatch
import app.revanced.patches.shared.litho.addLithoFilter
import app.revanced.patches.shared.litho.lithoFilterPatch
import app.revanced.util.findMethodOrThrow
import app.revanced.util.fingerprint.matchOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.getReference
Expand Down Expand Up @@ -58,32 +56,6 @@ val actionBarComponentsPatch = bytecodePatch(

execute {
if (is_7_17_or_greater) {
browseSectionListReloadEndpointFingerprint.methodOrThrow().apply {
val targetIndex = indexOfGetLithoViewFromMapInstruction(this)
val targetReference = getInstruction<ReferenceInstruction>(targetIndex).reference

findMethodOrThrow(ACTIONBAR_CLASS_DESCRIPTOR) {
name == "getLithoViewFromMap"
}.addInstructions(
0, """
invoke-static {p0, p1, p2}, $targetReference
move-result-object p1
return-object p1
"""
)
}

offlineVideoEndpointFingerprint.methodOrThrow().apply {
addInstructionsWithLabels(
0, """
invoke-static {p2}, $ACTIONBAR_CLASS_DESCRIPTOR->inAppDownloadButtonOnClick(Ljava/util/Map;)Z
move-result v0
if-eqz v0, :ignore
return-void
""", ExternalLabel("ignore", getInstruction(0))
)
}

addLithoFilter(FILTER_CLASS_DESCRIPTOR)
}

Expand Down Expand Up @@ -223,17 +195,17 @@ val actionBarComponentsPatch = bytecodePatch(
"revanced_hide_action_button_label",
"false"
)
addSwitchPreference(
CategoryType.ACTION_BAR,
"revanced_external_downloader_action",
"false"
)
addPreferenceWithIntent(
CategoryType.ACTION_BAR,
"revanced_external_downloader_package_name",
"revanced_external_downloader_action"
)
}
addSwitchPreference(
CategoryType.ACTION_BAR,
"revanced_external_downloader_action",
"false"
)
addPreferenceWithIntent(
CategoryType.ACTION_BAR,
"revanced_external_downloader_package_name",
"revanced_external_downloader_action"
)

updatePatchStatus(HIDE_ACTION_BAR_COMPONENTS)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package app.revanced.patches.music.actionbar.components

import app.revanced.patches.music.utils.resourceid.likeDislikeContainer
import app.revanced.util.fingerprint.legacyFingerprint
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

internal val actionBarComponentFingerprint = legacyFingerprint(
name = "actionBarComponentFingerprint",
Expand All @@ -26,40 +22,9 @@ internal val actionBarComponentFingerprint = legacyFingerprint(
literals = listOf(99180L),
)

internal val browseSectionListReloadEndpointFingerprint = legacyFingerprint(
name = "browseSectionListReloadEndpointFingerprint",
returnType = "V",
parameters = listOf("L", "Ljava/util/Map;"),
strings = listOf("request_mutator"),
customFingerprint = { method, _ ->
indexOfGetLithoViewFromMapInstruction(method) >= 0
}
)

internal fun indexOfGetLithoViewFromMapInstruction(method: Method) =
method.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_STATIC &&
reference?.returnType == "Ljava/lang/Object;" &&
reference.parameterTypes ==
listOf(
"Ljava/util/Map;",
"Ljava/lang/Object;",
"Ljava/lang/Class;"
)
}

internal val likeDislikeContainerFingerprint = legacyFingerprint(
name = "likeDislikeContainerFingerprint",
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
literals = listOf(likeDislikeContainer)
)

internal val offlineVideoEndpointFingerprint = legacyFingerprint(
name = "offlineVideoEndpointFingerprint",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "V",
parameters = listOf("L", "Ljava/util/Map;"),
strings = listOf("Object is not an offlineable video: %s")
)

0 comments on commit 16ead35

Please sign in to comment.