refactor(Spotify): Add extensions debug logging (#5110)

This commit is contained in:
Nuckyz
2025-06-05 16:04:02 -03:00
committed by GitHub
parent 617d925fcf
commit f2ca0eeac0
10 changed files with 101 additions and 27 deletions

View File

@ -6,7 +6,7 @@ dependencies {
android {
defaultConfig {
minSdk = 24
minSdk = 21
}
compileOptions {

View File

@ -2,6 +2,7 @@ package app.revanced.extension.spotify.layout.hide.createbutton;
import java.util.List;
import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
@SuppressWarnings("unused")
@ -31,10 +32,21 @@ public final class HideCreateButtonPatch {
}
String stringifiedNavigationBarItem = navigationBarItem.toString();
boolean isCreateButton = CREATE_BUTTON_TITLE_RES_ID_LIST.stream()
.anyMatch(stringifiedNavigationBarItem::contains);
boolean isCreateButton = false;
String matchedTitleResId = null;
for (String titleResId : CREATE_BUTTON_TITLE_RES_ID_LIST) {
if (stringifiedNavigationBarItem.contains(titleResId)) {
isCreateButton = true;
matchedTitleResId = titleResId;
}
}
if (isCreateButton) {
String finalMatchedTitleResId = matchedTitleResId;
Logger.printInfo(() -> "Hiding Create button because the navigation bar item " + navigationBarItem +
" matched the title resource id " + finalMatchedTitleResId);
return null;
}
@ -46,6 +58,14 @@ public final class HideCreateButtonPatch {
* Create button.
*/
public static boolean isOldCreateButton(int oldNavigationBarItemTitleResId) {
return oldNavigationBarItemTitleResId == OLD_CREATE_BUTTON_TITLE_RES_ID;
boolean isCreateButton = oldNavigationBarItemTitleResId == OLD_CREATE_BUTTON_TITLE_RES_ID;
if (isCreateButton) {
Logger.printInfo(() -> "Hiding old Create button because the navigation bar item title resource id" +
" matched " + OLD_CREATE_BUTTON_TITLE_RES_ID);
return true;
}
return false;
}
}

View File

@ -5,6 +5,7 @@ import static java.lang.Boolean.TRUE;
import com.spotify.home.evopage.homeapi.proto.Section;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -133,17 +134,33 @@ public final class UnlockPremiumPatch {
try {
for (OverrideAttribute override : PREMIUM_OVERRIDES) {
Object attribute = attributes.get(override.key);
if (attribute == null) {
if (override.isExpected) {
Logger.printException(() -> "'" + override.key + "' expected but not found");
Logger.printException(() -> "Attribute " + override.key + " expected but not found");
}
continue;
}
Object overrideValue = override.overrideValue;
Object originalValue;
if (IS_SPOTIFY_LEGACY_APP_TARGET) {
originalValue = ((com.spotify.useraccount.v1.AccountAttribute) attribute).value_;
} else {
Object overrideValue = override.overrideValue;
if (IS_SPOTIFY_LEGACY_APP_TARGET) {
((com.spotify.useraccount.v1.AccountAttribute) attribute).value_ = overrideValue;
} else {
((com.spotify.remoteconfig.internal.AccountAttribute) attribute).value_ = overrideValue;
}
originalValue = ((com.spotify.remoteconfig.internal.AccountAttribute) attribute).value_;
}
if (overrideValue == originalValue) {
continue;
}
Logger.printInfo(() -> "Overriding account attribute " + override.key +
" from " + originalValue + " to " + overrideValue);
if (IS_SPOTIFY_LEGACY_APP_TARGET) {
((com.spotify.useraccount.v1.AccountAttribute) attribute).value_ = overrideValue;
} else {
((com.spotify.remoteconfig.internal.AccountAttribute) attribute).value_ = overrideValue;
}
}
} catch (Exception ex) {
@ -155,7 +172,13 @@ public final class UnlockPremiumPatch {
* Injection point. Remove station data from Google Assistant URI.
*/
public static String removeStationString(String spotifyUriOrUrl) {
return spotifyUriOrUrl.replace("spotify:station:", "spotify:");
try {
Logger.printInfo(() -> "Removing station string from " + spotifyUriOrUrl);
return spotifyUriOrUrl.replace("spotify:station:", "spotify:");
} catch (Exception ex) {
Logger.printException(() -> "removeStationString failure", ex);
return spotifyUriOrUrl;
}
}
/**
@ -164,9 +187,17 @@ public final class UnlockPremiumPatch {
*/
public static void removeHomeSections(List<Section> sections) {
try {
sections.removeIf(section -> REMOVED_HOME_SECTIONS.contains(section.featureTypeCase_));
Iterator<Section> iterator = sections.iterator();
while (iterator.hasNext()) {
Section section = iterator.next();
if (REMOVED_HOME_SECTIONS.contains(section.featureTypeCase_)) {
Logger.printInfo(() -> "Removing home section with feature type id " + section.featureTypeCase_);
iterator.remove();
}
}
} catch (Exception ex) {
Logger.printException(() -> "Remove home sections failure", ex);
Logger.printException(() -> "removeHomeSections failure", ex);
}
}
@ -179,7 +210,30 @@ public final class UnlockPremiumPatch {
}
String stringifiedContextMenuItem = contextMenuItem.toString();
return FILTERED_CONTEXT_MENU_ITEMS_BY_STRINGS.stream()
.anyMatch(filters -> filters.stream().allMatch(stringifiedContextMenuItem::contains));
for (List<String> stringList : FILTERED_CONTEXT_MENU_ITEMS_BY_STRINGS) {
boolean allMatch = true;
StringBuilder matchedStrings = new StringBuilder();
for (int i = 0; i < stringList.size(); i++) {
String string = stringList.get(i);
if (!stringifiedContextMenuItem.contains(string)) {
allMatch = false;
break;
}
matchedStrings.append(string);
if (i < stringList.size() - 1) {
matchedStrings.append(", ");
}
}
if (allMatch) {
Logger.printInfo(() -> "Filtering context menu item " + stringifiedContextMenuItem +
" because the following strings matched: " + matchedStrings);
return true;
}
}
return false;
}
}

View File

@ -33,10 +33,11 @@ public final class SanitizeSharingLinksPatch {
}
}
return builder.build().toString();
String sanitizedUrl = builder.build().toString();
Logger.printInfo(() -> "Sanitized url " + url + " to " + sanitizedUrl);
return sanitizedUrl;
} catch (Exception ex) {
Logger.printException(() -> "sanitizeUrl failure", ex);
Logger.printException(() -> "sanitizeUrl failure with " + url, ex);
return url;
}
}

View File

@ -7,7 +7,7 @@ android {
compileSdk = 34
defaultConfig {
minSdk = 24
minSdk = 21
}
compileOptions {