Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
Fix incognito mode litho Shorts using wrong data
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Oct 12, 2023
1 parent ad65a8e commit 4884bfe
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@ public static CharSequence onLithoTextLoaded(@NonNull Object conversionContext,
}
ReturnYouTubeDislike videoData = lastLithoShortsVideoData;
if (videoData == null) {
// Somehow the litho video id filter did not detect the video id.
LogHelper.printDebug(() -> "Error: Litho video data is null, but it should not be");
// The Shorts litho video id filter did not detect the video id.
// This is normal if in incognito mode, but otherwise is not normal.
LogHelper.printDebug(() -> "Cannot modify Shorts litho span, data is null");
return original;
}
// Use the correct dislikes data after voting.
Expand Down Expand Up @@ -437,7 +438,10 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith
if (!SettingsEnum.RYD_ENABLED.getBoolean()) return;

PlayerType currentPlayerType = PlayerType.getCurrent();
if (currentPlayerType.isNoneOrHidden() && !SettingsEnum.RYD_SHORTS.getBoolean()) {
final boolean isNoneHiddenOrSlidingMinimized = currentPlayerType.isNoneHiddenOrSlidingMinimized();
if (isNoneHiddenOrSlidingMinimized && !SettingsEnum.RYD_SHORTS.getBoolean()) {
// Must clear here, otherwise the wrong data can be used for a minimized regular video.
currentVideoData = null;
return;
}

Expand All @@ -450,7 +454,7 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith
// Litho filter did not detect the video id. App is in incognito mode,
// or the proto buffer structure was changed and the video id is no longer present.
// Must clear both currently playing and last litho data otherwise the
// next regular video may use the wrong data
// next regular video may use the wrong data.
LogHelper.printDebug(() -> "Litho filter did not find any video ids");
currentVideoData = null;
lastLithoShortsVideoData = null;
Expand All @@ -468,21 +472,30 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith
return;
}
currentVideoData = ReturnYouTubeDislike.getFetchForVideoId(videoId);
// Pre-emptively set the data to short status.
// Required to prevent Shorts data from being used on a minimized video in incognito mode.
if (isNoneHiddenOrSlidingMinimized) {
// Short is playing with a regular video minimized.
currentVideoData.setVideoIdIsShort(true);
}
}

LogHelper.printDebug(() -> "New video id: " + videoId + " playerType: " + currentPlayerType
+ " isShortsLithoHook: " + isShortsLithoVideoId);

// Current video id hook can be called out of order with the non litho Shorts text view hook.
// Must manually update again here.
updateOnScreenShortsTextViews(true);
if (!isShortsLithoVideoId && isNoneHiddenOrSlidingMinimized) {
updateOnScreenShortsTextViews(true);
}
} catch (Exception ex) {
LogHelper.printException(() -> "newVideoLoaded failure", ex);
}
}

private static boolean videoIdIsSame(@Nullable ReturnYouTubeDislike fetch, String videoId) {
return fetch != null && fetch.getVideoId().equals(videoId);
private static boolean videoIdIsSame(@Nullable ReturnYouTubeDislike fetch, @Nullable String videoId) {
return (fetch == null && videoId == null)
|| (fetch != null && fetch.getVideoId().equals(videoId));
}

/**
Expand Down Expand Up @@ -511,10 +524,13 @@ public static void sendVote(int vote) {
if (v.value == vote) {
videoData.sendVote(v);

if (isNoneHiddenOrMinimized && lastLithoShortsVideoData != null) {
lithoShortsShouldUseCurrentData = true;
if (isNoneHiddenOrMinimized) {
if (lastLithoShortsVideoData != null) {
lithoShortsShouldUseCurrentData = true;
}
updateOldUIDislikesTextView();
}
updateOldUIDislikesTextView();

return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* that makes the value of {@link VideoInformation#getVideoId()} and {@link VideoInformation#getPlayerResponseVideoId()}
* unreliable to determine which video id a Shorts litho span belongs to.
*
* But the correct video id does appear in the protobuffer just before any litho span is created.
* But the correct video id does appear in the protobuffer just before a Shorts litho span is created.
*
* Once a way to asynchronously update litho text is found, this strategy will no longer be needed.
*/
Expand Down Expand Up @@ -91,6 +91,8 @@ public boolean isFiltered(@Nullable String identifier, String path, byte[] proto
String matchedVideoId = findVideoId(protobufBufferArray);
// Matched video will be null if in incognito mode.
// Must pass a null id to correctly clear out the current video data.
// Otherwise if a Short is opened in non-incognito, then incognito is enabled and another Short is opened,
// the new incognito Short will show the old prior data.
ReturnYouTubeDislikePatch.newVideoLoaded(matchedVideoId, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public enum Vote {
/**
* If this instance was previously used for a Short.
*/
@Nullable
@GuardedBy("this")
private boolean isShort;

Expand Down Expand Up @@ -421,7 +420,6 @@ public String getVideoId() {

/**
* Pre-emptively set this as a Short.
* Should only be used immediately after creation of this instance.
*/
public synchronized void setVideoIdIsShort(boolean isShort) {
this.isShort = isShort;
Expand Down Expand Up @@ -475,11 +473,11 @@ private Spanned waitForFetchAndUpdateReplacementSpan(@NonNull Spanned original,

if (originalDislikeSpan != null && replacementLikeDislikeSpan != null) {
if (spansHaveEqualTextAndColor(original, replacementLikeDislikeSpan)) {
LogHelper.printDebug(() -> "Ignoring previously created dislikes span");
LogHelper.printDebug(() -> "Ignoring previously created dislikes span of data: " + videoId);
return original;
}
if (spansHaveEqualTextAndColor(original, originalDislikeSpan)) {
LogHelper.printDebug(() -> "Replacing span with previously created dislike span");
LogHelper.printDebug(() -> "Replacing span with previously created dislike span of data: " + videoId);
return replacementLikeDislikeSpan;
}
}
Expand Down Expand Up @@ -518,7 +516,7 @@ public void sendVote(@NonNull Vote vote) {
if (isShort != PlayerType.getCurrent().isNoneOrHidden()) {
// Shorts was loaded with regular video present, then Shorts was closed.
// and then user voted on the now visible original video.
// Cannot send a vote, because the loaded videoId is for the wrong video.
// Cannot send a vote, because this instance is for the wrong video.
ReVancedUtils.showToastLong(str("revanced_ryd_failure_ryd_enabled_while_playing_video_then_user_voted"));
return;
}
Expand Down
24 changes: 19 additions & 5 deletions app/src/main/java/app/revanced/integrations/shared/PlayerType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ enum class PlayerType {
WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN,
WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED,
/**
* When opening a short while a regular video is minimized, the type can momentarily be this.
* Player is either sliding to [HIDDEN] state because a Short was opened while a regular video is on screen.
* OR
* The user has swiped a minimized player away to be closed (and no Short is being opened).
*/
WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED,
WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED,
Expand Down Expand Up @@ -84,20 +86,32 @@ enum class PlayerType {
return this == NONE || this == HIDDEN
}

/**
* Check if the current player type is
* [NONE], [HIDDEN], [WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED].
*
* Useful to check if a Short is being played, and usually covers all use cases
* except for some hooks when spoofing to an old version (where the type can be [WATCH_WHILE_MINIMIZED].
*
* @return If nothing, a Short, or a regular video is sliding off screen to a dismissed or hidden state.
*/
fun isNoneHiddenOrSlidingMinimized(): Boolean {
return isNoneOrHidden() || this == WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED
}

/**
* Check if the current player type is
* [NONE], [HIDDEN], [WATCH_WHILE_MINIMIZED], [WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED].
*
* Useful to check if a Short is being played,
* although will return false positive if a regular video is opened and minimized (and no short is playing).
* although will return false positive if a regular video is
* opened and minimized (and a Short is not playing or being opened).
*
* @return If nothing, a Short,
* or a regular video is minimized video or sliding off screen to a dismissed or hidden state.
*/
fun isNoneHiddenOrMinimized(): Boolean {
return this == NONE || this == HIDDEN
|| this == WATCH_WHILE_MINIMIZED
|| this == WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED
return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED
}

}

0 comments on commit 4884bfe

Please sign in to comment.